//ui
function(e, t) {
    function i(t, n) {
        var r,
        i,
        o,
        u = t.nodeName.toLowerCase();
        return "area" === u ? (r = t.parentNode, i = r.name, !t.href || !i || r.nodeName.toLowerCase() !== "map" ? !1: (o = e("img[usemap=#" + i + "]")[0], !!o && s(o))) : (/input|select|textarea|button|object/.test(u) ? !t.disabled: "a" === u ? t.href || n: n) && s(t)
    }
    function s(t) {
        return e.expr.filters.visible(t) && !e(t).parents().andSelf().filter(function() {
            return e.css(this, "visibility") === "hidden"
        }).length
    }
    var n = 0,
    r = /^ui-id-\d+$/;
    e.ui = e.ui || {};
    if (e.ui.version) return;
    e.extend(e.ui, {
        version: "1.9.2",
        keyCode: {
            BACKSPACE: 8,
            COMMA: 188,
            DELETE: 46,
            DOWN: 40,
            END: 35,
            ENTER: 13,
            ESCAPE: 27,
            HOME: 36,
            LEFT: 37,
            NUMPAD_ADD: 107,
            NUMPAD_DECIMAL: 110,
            NUMPAD_DIVIDE: 111,
            NUMPAD_ENTER: 108,
            NUMPAD_MULTIPLY: 106,
            NUMPAD_SUBTRACT: 109,
            PAGE_DOWN: 34,
            PAGE_UP: 33,
            PERIOD: 190,
            RIGHT: 39,
            SPACE: 32,
            TAB: 9,
            UP: 38
        }
    }),
    e.fn.extend({
        _focus: e.fn.focus,
        focus: function(t, n) {
            return typeof t == "number" ? this.each(function() {
                var r = this;
                setTimeout(function() {
                    e(r).focus(),
                    n && n.call(r)
                },
                t)
            }) : this._focus.apply(this, arguments)
        },
        scrollParent: function() {
            var t;
            return e.ui.ie && /(static|relative)/.test(this.css("position")) || /absolute/.test(this.css("position")) ? t = this.parents().filter(function() {
                return /(relative|absolute|fixed)/.test(e.css(this, "position")) && /(auto|scroll)/.test(e.css(this, "overflow") + e.css(this, "overflow-y") + e.css(this, "overflow-x"))
            }).eq(0) : t = this.parents().filter(function() {
                return /(auto|scroll)/.test(e.css(this, "overflow") + e.css(this, "overflow-y") + e.css(this, "overflow-x"))
            }).eq(0),
            /fixed/.test(this.css("position")) || !t.length ? e(document) : t
        },
        zIndex: function(n) {
            if (n !== t) return this.css("zIndex", n);
            if (this.length) {
                var r = e(this[0]),
                i,
                s;
                while (r.length && r[0] !== document) {
                    i = r.css("position");
                    if (i === "absolute" || i === "relative" || i === "fixed") {
                        s = parseInt(r.css("zIndex"), 10);
                        if (!isNaN(s) && s !== 0) return s
                    }
                    r = r.parent()
                }
            }
            return 0
        },
        uniqueId: function() {
            return this.each(function() {
                this.id || (this.id = "ui-id-" + ++n)
            })
        },
        removeUniqueId: function() {
            return this.each(function() {
                r.test(this.id) && e(this).removeAttr("id")
            })
        }
    }),
    e.extend(e.expr[":"], {
        data: e.expr.createPseudo ? e.expr.createPseudo(function(t) {
            return function(n) {
                return !! e.data(n, t)
            }
        }) : function(t, n, r) {
            return !! e.data(t, r[3])
        },
        focusable: function(t) {
            return i(t, !isNaN(e.attr(t, "tabindex")))
        },
        tabbable: function(t) {
            var n = e.attr(t, "tabindex"),
            r = isNaN(n);
            return (r || n >= 0) && i(t, !r)
        }
    }),
    e(function() {
        var t = document.body,
        n = t.appendChild(n = document.createElement("div"));
        n.offsetHeight,
        e.extend(n.style, {
            minHeight: "100px",
            height: "auto",
            padding: 0,
            borderWidth: 0
        }),
        e.support.minHeight = n.offsetHeight === 100,
        e.support.selectstart = "onselectstart" in n,
        t.removeChild(n).style.display = "none"
    }),
    e("<a>").outerWidth(1).jquery || e.each(["Width", "Height"], 
    function(n, r) {
        function u(t, n, r, s) {
            return e.each(i, 
            function() {
                n -= parseFloat(e.css(t, "padding" + this)) || 0,
                r && (n -= parseFloat(e.css(t, "border" + this + "Width")) || 0),
                s && (n -= parseFloat(e.css(t, "margin" + this)) || 0)
            }),
            n
        }
        var i = r === "Width" ? ["Left", "Right"] : ["Top", "Bottom"],
        s = r.toLowerCase(),
        o = {
            innerWidth: e.fn.innerWidth,
            innerHeight: e.fn.innerHeight,
            outerWidth: e.fn.outerWidth,
            outerHeight: e.fn.outerHeight
        };
        e.fn["inner" + r] = function(n) {
            return n === t ? o["inner" + r].call(this) : this.each(function() {
                e(this).css(s, u(this, n) + "px")
            })
        },
        e.fn["outer" + r] = function(t, n) {
            return typeof t != "number" ? o["outer" + r].call(this, t) : this.each(function() {
                e(this).css(s, u(this, t, !0, n) + "px")
            })
        }
    }),
    e("<a>").data("a-b", "a").removeData("a-b").data("a-b") && (e.fn.removeData = function(t) {
        return function(n) {
            return arguments.length ? t.call(this, e.camelCase(n)) : t.call(this)
        }
    } (e.fn.removeData)),
    function() {
        var t = /msie ([\w.]+)/.exec(navigator.userAgent.toLowerCase()) || [];
        e.ui.ie = t.length ? !0: !1,
        e.ui.ie6 = parseFloat(t[1], 10) === 6
    } (),
    e.fn.extend({
        disableSelection: function() {
            return this.bind((e.support.selectstart ? "selectstart": "mousedown") + ".ui-disableSelection", 
            function(e) {
                e.preventDefault()
            })
        },
        enableSelection: function() {
            return this.unbind(".ui-disableSelection")
        }
    }),
    e.extend(e.ui, {
        plugin: {
            add: function(t, n, r) {
                var i,
                s = e.ui[t].prototype;
                for (i in r) s.plugins[i] = s.plugins[i] || [],
                s.plugins[i].push([n, r[i]])
            },
            call: function(e, t, n) {
                var r,
                i = e.plugins[t];
                if (!i || !e.element[0].parentNode || e.element[0].parentNode.nodeType === 11) return;
                for (r = 0; r < i.length; r++) e.options[i[r][0]] && i[r][1].apply(e.element, n)
            }
        },
        contains: e.contains,
        hasScroll: function(t, n) {
            if (e(t).css("overflow") === "hidden") return ! 1;
            var r = n && n === "left" ? "scrollLeft": "scrollTop",
            i = !1;
            return t[r] > 0 ? !0: (t[r] = 1, i = t[r] > 0, t[r] = 0, i)
        },
        isOverAxis: function(e, t, n) {
            return e > t && e < t + n
        },
        isOver: function(t, n, r, i, s, o) {
            return e.ui.isOverAxis(t, r, s) && e.ui.isOverAxis(n, i, o)
        }
    })
} (jQuery),
//widget
function(e, t) {
    var n = 0,
    r = Array.prototype.slice,
    i = e.cleanData;
    e.cleanData = function(t) {
        for (var n = 0, r; (r = t[n]
        ) != null; n++) try {
            e(r).triggerHandler("remove")
        } catch(s) {}
        i(t)
    },
    e.widget = function(t, n, r) {
        var i,
        s,
        o,
        u,
        a = t.split(".")[0];
        t = t.split(".")[1],
        i = a + "-" + t,
        r || (r = n, n = e.Widget),
        e.expr[":"][i.toLowerCase()] = function(t) {
            return !! e.data(t, i)
        },
        e[a] = e[a] || {},
        s = e[a][t],
        o = e[a][t] = function(e, t) {
            if (!this._createWidget) return new o(e, t);
            arguments.length && this._createWidget(e, t)
        },
        e.extend(o, s, {
            version: r.version,
            _proto: e.extend({},
            r),
            _childConstructors: []
        }),
        u = new n,
        u.options = e.widget.extend({},
        u.options),
        e.each(r, 
        function(t, i) {
            e.isFunction(i) && (r[t] = function() {
                var e = function() {
                    return n.prototype[t].apply(this, arguments)
                },
                r = function(e) {
                    return n.prototype[t].apply(this, e)
                };
                return function() {
                    var t = this._super,
                    n = this._superApply,
                    s;
                    return this._super = e,
                    this._superApply = r,
                    s = i.apply(this, arguments),
                    this._super = t,
                    this._superApply = n,
                    s
                }
            } ())
        }),
        o.prototype = e.widget.extend(u, {
            widgetEventPrefix: s ? u.widgetEventPrefix: t
        },
        r, {
            constructor: o,
            namespace: a,
            widgetName: t,
            widgetBaseClass: i,
            widgetFullName: i
        }),
        s ? (e.each(s._childConstructors, 
        function(t, n) {
            var r = n.prototype;
            e.widget(r.namespace + "." + r.widgetName, o, n._proto)
        }), delete s._childConstructors) : n._childConstructors.push(o),
        e.widget.bridge(t, o)
    },
    e.widget.extend = function(n) {
        var i = r.call(arguments, 1),
        s = 0,
        o = i.length,
        u,
        a;
        for (; s < o; s++) for (u in i[s]) a = i[s][u],
        i[s].hasOwnProperty(u) && a !== t && (e.isPlainObject(a) ? n[u] = e.isPlainObject(n[u]) ? e.widget.extend({},
        n[u], a) : e.widget.extend({},
        a) : n[u] = a);
        return n
    },
    e.widget.bridge = function(n, i) {
        var s = i.prototype.widgetFullName || n;
        e.fn[n] = function(o) {
            var u = typeof o == "string",
            a = r.call(arguments, 1),
            f = this;
            return o = !u && a.length ? e.widget.extend.apply(null, [o].concat(a)) : o,
            u ? this.each(function() {
                var r,
                i = e.data(this, s);
                if (!i) return e.error("cannot call methods on " + n + " prior to initialization; " + "attempted to call method '" + o + "'");
                if (!e.isFunction(i[o]) || o.charAt(0) === "_") return e.error("no such method '" + o + "' for " + n + " widget instance");
                r = i[o].apply(i, a);
                if (r !== i && r !== t) return f = r && r.jquery ? f.pushStack(r.get()) : r,
                !1
            }) : this.each(function() {
                var t = e.data(this, s);
                t ? t.option(o || {})._init() : e.data(this, s, new i(o, this))
            }),
            f
        }
    },
    e.Widget = function() {},
    e.Widget._childConstructors = [],
    e.Widget.prototype = {
        widgetName: "widget",
        widgetEventPrefix: "",
        defaultElement: "<div>",
        options: {
            disabled: !1,
            create: null
        },
        _createWidget: function(t, r) {
            r = e(r || this.defaultElement || this)[0],
            this.element = e(r),
            this.uuid = n++,
            this.eventNamespace = "." + this.widgetName + this.uuid,
            this.options = e.widget.extend({},
            this.options, this._getCreateOptions(), t),
            this.bindings = e(),
            this.hoverable = e(),
            this.focusable = e(),
            r !== this && (e.data(r, this.widgetName, this), e.data(r, this.widgetFullName, this), this._on(!0, this.element, {
                remove: function(e) {
                    e.target === r && this.destroy()
                }
            }), this.document = e(r.style ? r.ownerDocument: r.document || r), this.window = e(this.document[0].defaultView || this.document[0].parentWindow)),
            this._create(),
            this._trigger("create", null, this._getCreateEventData()),
            this._init()
        },
        _getCreateOptions: e.noop,
        _getCreateEventData: e.noop,
        _create: e.noop,
        _init: e.noop,
        destroy: function() {
            this._destroy(),
            this.element.unbind(this.eventNamespace).removeData(this.widgetName).removeData(this.widgetFullName).removeData(e.camelCase(this.widgetFullName)),
            this.widget().unbind(this.eventNamespace).removeAttr("aria-disabled").removeClass(this.widgetFullName + "-disabled " + "ui-state-disabled"),
            this.bindings.unbind(this.eventNamespace),
            this.hoverable.removeClass("ui-state-hover"),
            this.focusable.removeClass("ui-state-focus")
        },
        _destroy: e.noop,
        widget: function() {
            return this.element
        },
        option: function(n, r) {
            var i = n,
            s,
            o,
            u;
            if (arguments.length === 0) return e.widget.extend({},
            this.options);
            if (typeof n == "string") {
                i = {},
                s = n.split("."),
                n = s.shift();
                if (s.length) {
                    o = i[n] = e.widget.extend({},
                    this.options[n]);
                    for (u = 0; u < s.length - 1; u++) o[s[u]] = o[s[u]] || {},
                    o = o[s[u]];
                    n = s.pop();
                    if (r === t) return o[n] === t ? null: o[n];
                    o[n] = r
                } else {
                    if (r === t) return this.options[n] === t ? null: this.options[n];
                    i[n] = r
                }
            }
            return this._setOptions(i),
            this
        },
        _setOptions: function(e) {
            var t;
            for (t in e) this._setOption(t, e[t]);
            return this
        },
        _setOption: function(e, t) {
            return this.options[e] = t,
            e === "disabled" && (this.widget().toggleClass(this.widgetFullName + "-disabled ui-state-disabled", !!t).attr("aria-disabled", t), this.hoverable.removeClass("ui-state-hover"), this.focusable.removeClass("ui-state-focus")),
            this
        },
        enable: function() {
            return this._setOption("disabled", !1)
        },
        disable: function() {
            return this._setOption("disabled", !0)
        },
        _on: function(t, n, r) {
            var i,
            s = this;
            typeof t != "boolean" && (r = n, n = t, t = !1),
            r ? (n = i = e(n), this.bindings = this.bindings.add(n)) : (r = n, n = this.element, i = this.widget()),
            e.each(r, 
            function(r, o) {
                function u() {
                    if (!t && (s.options.disabled === !0 || e(this).hasClass("ui-state-disabled"))) return;
                    return (typeof o == "string" ? s[o] : o).apply(s, arguments)
                }
                typeof o != "string" && (u.guid = o.guid = o.guid || u.guid || e.guid++);
                var a = r.match(/^(\w+)\s*(.*)$/),
                f = a[1] + s.eventNamespace,
                l = a[2];
                l ? i.delegate(l, f, u) : n.bind(f, u)
            })
        },
        _off: function(e, t) {
            t = (t || "").split(" ").join(this.eventNamespace + " ") + this.eventNamespace,
            e.unbind(t).undelegate(t)
        },
        _delay: function(e, t) {
            function n() {
                return (typeof e == "string" ? r[e] : e).apply(r, arguments)
            }
            var r = this;
            return setTimeout(n, t || 0)
        },
        _hoverable: function(t) {
            this.hoverable = this.hoverable.add(t),
            this._on(t, {
                mouseenter: function(t) {
                    e(t.currentTarget).addClass("ui-state-hover")
                },
                mouseleave: function(t) {
                    e(t.currentTarget).removeClass("ui-state-hover")
                }
            })
        },
        _focusable: function(t) {
            this.focusable = this.focusable.add(t),
            this._on(t, {
                focusin: function(t) {
                    e(t.currentTarget).addClass("ui-state-focus")
                },
                focusout: function(t) {
                    e(t.currentTarget).removeClass("ui-state-focus")
                }
            })
        },
        _trigger: function(t, n, r) {
            var i,
            s,
            o = this.options[t];
            r = r || {},
            n = e.Event(n),
            n.type = (t === this.widgetEventPrefix ? t: this.widgetEventPrefix + t).toLowerCase(),
            n.target = this.element[0],
            s = n.originalEvent;
            if (s) for (i in s) i in n || (n[i] = s[i]);
            return this.element.trigger(n, r),
            !(e.isFunction(o) && o.apply(this.element[0], [n].concat(r)) === !1 || n.isDefaultPrevented())
        }
    },
    e.each({
        show: "fadeIn",
        hide: "fadeOut"
    },
    function(t, n) {
        e.Widget.prototype["_" + t] = function(r, i, s) {
            typeof i == "string" && (i = {
                effect: i
            });
            var o,
            u = i ? i === !0 || typeof i == "number" ? n: i.effect || n: t;
            i = i || {},
            typeof i == "number" && (i = {
                duration: i
            }),
            o = !e.isEmptyObject(i),
            i.complete = s,
            i.delay && r.delay(i.delay),
            o && e.effects && (e.effects.effect[u] || e.uiBackCompat !== !1 && e.effects[u]) ? r[t](i) : u !== t && r[u] ? r[u](i.duration, i.easing, s) : r.queue(function(n) {
                e(this)[t](),
                s && s.call(r[0]),
                n()
            })
        }
    }),
    e.uiBackCompat !== !1 && (e.Widget.prototype._getCreateOptions = function() {
        return e.metadata && e.metadata.get(this.element[0])[this.widgetName]
    })
} (jQuery),
//Mouse
function(e, t) {
    var n = !1;
    e(document).mouseup(function(e) {
        n = !1
    }),
    e.widget("ui.mouse", {
        version: "1.9.2",
        options: {
            cancel: "input,textarea,button,select,option",
            distance: 1,
            delay: 0
        },
        _mouseInit: function() {
            var t = this;
            this.element.bind("mousedown." + this.widgetName, 
            function(e) {
                return t._mouseDown(e)
            }).bind("click." + this.widgetName, 
            function(n) {
                if (!0 === e.data(n.target, t.widgetName + ".preventClickEvent")) return e.removeData(n.target, t.widgetName + ".preventClickEvent"),
                n.stopImmediatePropagation(),
                !1
            }),
            this.started = !1
        },
        _mouseDestroy: function() {
            this.element.unbind("." + this.widgetName),
            this._mouseMoveDelegate && e(document).unbind("mousemove." + this.widgetName, this._mouseMoveDelegate).unbind("mouseup." + this.widgetName, this._mouseUpDelegate)
        },
        _mouseDown: function(t) {
            if (n) return;
            this._mouseStarted && this._mouseUp(t),
            this._mouseDownEvent = t;
            var r = this,
            i = t.which === 1,
            s = typeof this.options.cancel == "string" && t.target.nodeName ? e(t.target).closest(this.options.cancel).length: !1;
            if (!i || s || !this._mouseCapture(t)) return ! 0;
            this.mouseDelayMet = !this.options.delay,
            this.mouseDelayMet || (this._mouseDelayTimer = setTimeout(function() {
                r.mouseDelayMet = !0
            },
            this.options.delay));
            if (this._mouseDistanceMet(t) && this._mouseDelayMet(t)) {
                this._mouseStarted = this._mouseStart(t) !== !1;
                if (!this._mouseStarted) return t.preventDefault(),
                !0
            }
            return ! 0 === e.data(t.target, this.widgetName + ".preventClickEvent") && e.removeData(t.target, this.widgetName + ".preventClickEvent"),
            this._mouseMoveDelegate = function(e) {
                return r._mouseMove(e)
            },
            this._mouseUpDelegate = function(e) {
                return r._mouseUp(e)
            },
            e(document).bind("mousemove." + this.widgetName, this._mouseMoveDelegate).bind("mouseup." + this.widgetName, this._mouseUpDelegate),
            t.preventDefault(),
            n = !0,
            !0
        },
        _mouseMove: function(t) {
            return ! e.ui.ie || document.documentMode >= 9 || !!t.button ? this._mouseStarted ? (this._mouseDrag(t), t.preventDefault()) : (this._mouseDistanceMet(t) && this._mouseDelayMet(t) && (this._mouseStarted = this._mouseStart(this._mouseDownEvent, t) !== !1, this._mouseStarted ? this._mouseDrag(t) : this._mouseUp(t)), !this._mouseStarted) : this._mouseUp(t)
        },
        _mouseUp: function(t) {
            return e(document).unbind("mousemove." + this.widgetName, this._mouseMoveDelegate).unbind("mouseup." + this.widgetName, this._mouseUpDelegate),
            this._mouseStarted && (this._mouseStarted = !1, t.target === this._mouseDownEvent.target && e.data(t.target, this.widgetName + ".preventClickEvent", !0), this._mouseStop(t)),
            !1
        },
        _mouseDistanceMet: function(e) {
            return Math.max(Math.abs(this._mouseDownEvent.pageX - e.pageX), Math.abs(this._mouseDownEvent.pageY - e.pageY)) >= this.options.distance
        },
        _mouseDelayMet: function(e) {
            return this.mouseDelayMet
        },
        _mouseStart: function(e) {},
        _mouseDrag: function(e) {},
        _mouseStop: function(e) {},
        _mouseCapture: function(e) {
            return ! 0
        }
    })
} (jQuery),
//Draggable
function(e, t) {
    e.widget("ui.draggable", e.ui.mouse, {
        version: "1.9.2",
        widgetEventPrefix: "drag",
        options: {
            addClasses: !0,
            appendTo: "parent",
            axis: !1,
            connectToSortable: !1,
            containment: !1,
            cursor: "auto",
            cursorAt: !1,
            grid: !1,
            handle: !1,
            helper: "original",
            iframeFix: !1,
            opacity: !1,
            refreshPositions: !1,
            revert: !1,
            revertDuration: 500,
            scope: "default",
            scroll: !0,
            scrollSensitivity: 20,
            scrollSpeed: 20,
            snap: !1,
            snapMode: "both",
            snapTolerance: 20,
            stack: !1,
            zIndex: !1
        },
        _create: function() {
            this.options.helper == "original" && !/^(?:r|a|f)/.test(this.element.css("position")) && (this.element[0].style.position = "relative"),
            this.options.addClasses && this.element.addClass("ui-draggable"),
            this.options.disabled && this.element.addClass("ui-draggable-disabled"),
            this._mouseInit()
        },
        _destroy: function() {
            this.element.removeClass("ui-draggable ui-draggable-dragging ui-draggable-disabled"),
            this._mouseDestroy()
        },
        _mouseCapture: function(t) {
            var n = this.options;
            return this.helper || n.disabled || e(t.target).is(".ui-resizable-handle") ? !1: (this.handle = this._getHandle(t), this.handle ? (e(n.iframeFix === !0 ? "iframe": n.iframeFix).each(function() {
                e('<div class="ui-draggable-iframeFix" style="background: #fff;"></div>').css({
                    width: this.offsetWidth + "px",
                    height: this.offsetHeight + "px",
                    position: "absolute",
                    opacity: "0.001",
                    zIndex: 1e3
                }).css(e(this).offset()).appendTo("body")
            }), !0) : !1)
        },
        _mouseStart: function(t) {
            var n = this.options;
            return this.helper = this._createHelper(t),
            this.helper.addClass("ui-draggable-dragging"),
            this._cacheHelperProportions(),
            e.ui.ddmanager && (e.ui.ddmanager.current = this),
            this._cacheMargins(),
            this.cssPosition = this.helper.css("position"),
            this.scrollParent = this.helper.scrollParent(),
            this.offset = this.positionAbs = this.element.offset(),
            this.offset = {
                top: this.offset.top - this.margins.top,
                left: this.offset.left - this.margins.left
            },
            e.extend(this.offset, {
                click: {
                    left: t.pageX - this.offset.left,
                    top: t.pageY - this.offset.top
                },
                parent: this._getParentOffset(),
                relative: this._getRelativeOffset()
            }),
            this.originalPosition = this.position = this._generatePosition(t),
            this.originalPageX = t.pageX,
            this.originalPageY = t.pageY,
            n.cursorAt && this._adjustOffsetFromHelper(n.cursorAt),
            n.containment && this._setContainment(),
            this._trigger("start", t) === !1 ? (this._clear(), !1) : (this._cacheHelperProportions(), e.ui.ddmanager && !n.dropBehaviour && e.ui.ddmanager.prepareOffsets(this, t), this._mouseDrag(t, !0), e.ui.ddmanager && e.ui.ddmanager.dragStart(this, t), !0)
        },
        _mouseDrag: function(t, n) {
            this.position = this._generatePosition(t),
            this.positionAbs = this._convertPositionTo("absolute");
            if (!n) {
                var r = this._uiHash();
                if (this._trigger("drag", t, r) === !1) return this._mouseUp({}),
                !1;
                this.position = r.position
            }
            if (!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left + "px";
            if (!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top + "px";
            return e.ui.ddmanager && e.ui.ddmanager.drag(this, t),
            !1
        },
        _mouseStop: function(t) {
            var n = !1;
            e.ui.ddmanager && !this.options.dropBehaviour && (n = e.ui.ddmanager.drop(this, t)),
            this.dropped && (n = this.dropped, this.dropped = !1);
            var r = this.element[0],
            i = !1;
            while (r && (r = r.parentNode)) r == document && (i = !0);
            if (!i && this.options.helper === "original") return ! 1;
            if (this.options.revert == "invalid" && !n || this.options.revert == "valid" && n || this.options.revert === !0 || e.isFunction(this.options.revert) && this.options.revert.call(this.element, n)) {
                var s = this;
                e(this.helper).animate(this.originalPosition, parseInt(this.options.revertDuration, 10), 
                function() {
                    s._trigger("stop", t) !== !1 && s._clear()
                })
            } else this._trigger("stop", t) !== !1 && this._clear();
            return ! 1
        },
        _mouseUp: function(t) {
            return e("div.ui-draggable-iframeFix").each(function() {
                this.parentNode.removeChild(this)
            }),
            e.ui.ddmanager && e.ui.ddmanager.dragStop(this, t),
            e.ui.mouse.prototype._mouseUp.call(this, t)
        },
        cancel: function() {
            return this.helper.is(".ui-draggable-dragging") ? this._mouseUp({}) : this._clear(),
            this
        },
        _getHandle: function(t) {
            var n = !this.options.handle || !e(this.options.handle, this.element).length ? !0: !1;
            return e(this.options.handle, this.element).find("*").andSelf().each(function() {
                this == t.target && (n = !0)
            }),
            n
        },
        _createHelper: function(t) {
            var n = this.options,
            r = e.isFunction(n.helper) ? e(n.helper.apply(this.element[0], [t])) : n.helper == "clone" ? this.element.clone().removeAttr("id") : this.element;
            return r.parents("body").length || r.appendTo(n.appendTo == "parent" ? this.element[0].parentNode: n.appendTo),
            r[0] != this.element[0] && !/(fixed|absolute)/.test(r.css("position")) && r.css("position", "absolute"),
            r
        },
        _adjustOffsetFromHelper: function(t) {
            typeof t == "string" && (t = t.split(" ")),
            e.isArray(t) && (t = {
                left: +t[0],
                top: +t[1] || 0
            }),
            "left" in t && (this.offset.click.left = t.left + this.margins.left),
            "right" in t && (this.offset.click.left = this.helperProportions.width - t.right + this.margins.left),
            "top" in t && (this.offset.click.top = t.top + this.margins.top),
            "bottom" in t && (this.offset.click.top = this.helperProportions.height - t.bottom + this.margins.top)
        },
        _getParentOffset: function() {
            this.offsetParent = this.helper.offsetParent();
            var t = this.offsetParent.offset();
            this.cssPosition == "absolute" && this.scrollParent[0] != document && e.contains(this.scrollParent[0], this.offsetParent[0]) && (t.left += this.scrollParent.scrollLeft(), t.top += this.scrollParent.scrollTop());
            if (this.offsetParent[0] == document.body || this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == "html" && e.ui.ie) t = {
                top: 0,
                left: 0
            };
            return {
                top: t.top + (parseInt(this.offsetParent.css("borderTopWidth"), 10) || 0),
                left: t.left + (parseInt(this.offsetParent.css("borderLeftWidth"), 10) || 0)
            }
        },
        _getRelativeOffset: function() {
            if (this.cssPosition == "relative") {
                var e = this.element.position();
                return {
                    top: e.top - (parseInt(this.helper.css("top"), 10) || 0) + this.scrollParent.scrollTop(),
                    left: e.left - (parseInt(this.helper.css("left"), 10) || 0) + this.scrollParent.scrollLeft()
                }
            }
            return {
                top: 0,
                left: 0
            }
        },
        _cacheMargins: function() {
            this.margins = {
                left: parseInt(this.element.css("marginLeft"), 10) || 0,
                top: parseInt(this.element.css("marginTop"), 10) || 0,
                right: parseInt(this.element.css("marginRight"), 10) || 0,
                bottom: parseInt(this.element.css("marginBottom"), 10) || 0
            }
        },
        _cacheHelperProportions: function() {
            this.helperProportions = {
                width: this.helper.outerWidth(),
                height: this.helper.outerHeight()
            }
        },
        _setContainment: function() {
            var t = this.options;
            t.containment == "parent" && (t.containment = this.helper[0].parentNode);
            if (t.containment == "document" || t.containment == "window") this.containment = [t.containment == "document" ? 0: e(window).scrollLeft() - this.offset.relative.left - this.offset.parent.left, t.containment == "document" ? 0: e(window).scrollTop() - this.offset.relative.top - this.offset.parent.top, (t.containment == "document" ? 0: e(window).scrollLeft()) + e(t.containment == "document" ? document: window).width() - this.helperProportions.width - this.margins.left, (t.containment == "document" ? 0: e(window).scrollTop()) + (e(t.containment == "document" ? document: window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top];
            if (!/^(document|window|parent)$/.test(t.containment) && t.containment.constructor != Array) {
                var n = e(t.containment),
                r = n[0];
                if (!r) return;
                var i = n.offset(),
                s = e(r).css("overflow") != "hidden";
                this.containment = [(parseInt(e(r).css("borderLeftWidth"), 10) || 0) + (parseInt(e(r).css("paddingLeft"), 10) || 0), (parseInt(e(r).css("borderTopWidth"), 10) || 0) + (parseInt(e(r).css("paddingTop"), 10) || 0), (s ? Math.max(r.scrollWidth, r.offsetWidth) : r.offsetWidth) - (parseInt(e(r).css("borderLeftWidth"), 10) || 0) - (parseInt(e(r).css("paddingRight"), 10) || 0) - this.helperProportions.width - this.margins.left - this.margins.right, (s ? Math.max(r.scrollHeight, r.offsetHeight) : r.offsetHeight) - (parseInt(e(r).css("borderTopWidth"), 10) || 0) - (parseInt(e(r).css("paddingBottom"), 10) || 0) - this.helperProportions.height - this.margins.top - this.margins.bottom],
                this.relative_container = n
            } else t.containment.constructor == Array && (this.containment = t.containment)
        },
        _convertPositionTo: function(t, n) {
            n || (n = this.position);
            var r = t == "absolute" ? 1: -1,
            i = this.options,
            s = this.cssPosition != "absolute" || this.scrollParent[0] != document && !!e.contains(this.scrollParent[0], this.offsetParent[0]) ? this.scrollParent: this.offsetParent,
            o = /(html|body)/i.test(s[0].tagName);
            return {
                top: n.top + this.offset.relative.top * r + this.offset.parent.top * r - (this.cssPosition == "fixed" ? -this.scrollParent.scrollTop() : o ? 0: s.scrollTop()) * r,
                left: n.left + this.offset.relative.left * r + this.offset.parent.left * r - (this.cssPosition == "fixed" ? -this.scrollParent.scrollLeft() : o ? 0: s.scrollLeft()) * r
            }
        },
        _generatePosition: function(t) {
            var n = this.options,
            r = this.cssPosition != "absolute" || this.scrollParent[0] != document && !!e.contains(this.scrollParent[0], this.offsetParent[0]) ? this.scrollParent: this.offsetParent,
            i = /(html|body)/i.test(r[0].tagName),
            s = t.pageX,
            o = t.pageY;
            if (this.originalPosition) {
                var u;
                if (this.containment) {
                    if (this.relative_container) {
                        var a = this.relative_container.offset();
                        u = [this.containment[0] + a.left, this.containment[1] + a.top, this.containment[2] + a.left, this.containment[3] + a.top]
                    } else u = this.containment;
                    t.pageX - this.offset.click.left < u[0] && (s = u[0] + this.offset.click.left),
                    t.pageY - this.offset.click.top < u[1] && (o = u[1] + this.offset.click.top),
                    t.pageX - this.offset.click.left > u[2] && (s = u[2] + this.offset.click.left),
                    t.pageY - this.offset.click.top > u[3] && (o = u[3] + this.offset.click.top)
                }
                if (n.grid) {
                    var f = n.grid[1] ? this.originalPageY + Math.round((o - this.originalPageY) / n.grid[1]) * n.grid[1] : this.originalPageY;
                    o = u ? f - this.offset.click.top < u[1] || f - this.offset.click.top > u[3] ? f - this.offset.click.top < u[1] ? f + n.grid[1] : f - n.grid[1] : f: f;
                    var l = n.grid[0] ? this.originalPageX + Math.round((s - this.originalPageX) / n.grid[0]) * n.grid[0] : this.originalPageX;
                    s = u ? l - this.offset.click.left < u[0] || l - this.offset.click.left > u[2] ? l - this.offset.click.left < u[0] ? l + n.grid[0] : l - n.grid[0] : l: l
                }
            }
            return {
                top: o - this.offset.click.top - this.offset.relative.top - this.offset.parent.top + (this.cssPosition == "fixed" ? -this.scrollParent.scrollTop() : i ? 0: r.scrollTop()),
                left: s - this.offset.click.left - this.offset.relative.left - this.offset.parent.left + (this.cssPosition == "fixed" ? -this.scrollParent.scrollLeft() : i ? 0: r.scrollLeft())
            }
        },
        _clear: function() {
            this.helper.removeClass("ui-draggable-dragging"),
            this.helper[0] != this.element[0] && !this.cancelHelperRemoval && this.helper.remove(),
            this.helper = null,
            this.cancelHelperRemoval = !1
        },
        _trigger: function(t, n, r) {
            return r = r || this._uiHash(),
            e.ui.plugin.call(this, t, [n, r]),
            t == "drag" && (this.positionAbs = this._convertPositionTo("absolute")),
            e.Widget.prototype._trigger.call(this, t, n, r)
        },
        plugins: {},
        _uiHash: function(e) {
            return {
                helper: this.helper,
                position: this.position,
                originalPosition: this.originalPosition,
                offset: this.positionAbs
            }
        }
    }),
    e.ui.plugin.add("draggable", "connectToSortable", {
        start: function(t, n) {
            var r = e(this).data("draggable"),
            i = r.options,
            s = e.extend({},
            n, {
                item: r.element
            });
            r.sortables = [],
            e(i.connectToSortable).each(function() {
                var n = e.data(this, "sortable");
                n && !n.options.disabled && (r.sortables.push({
                    instance: n,
                    shouldRevert: n.options.revert
                }), n.refreshPositions(), n._trigger("activate", t, s))
            })
        },
        stop: function(t, n) {
            var r = e(this).data("draggable"),
            i = e.extend({},
            n, {
                item: r.element
            });
            e.each(r.sortables, 
            function() {
                this.instance.isOver ? (this.instance.isOver = 0, r.cancelHelperRemoval = !0, this.instance.cancelHelperRemoval = !1, this.shouldRevert && (this.instance.options.revert = !0), this.instance._mouseStop(t), this.instance.options.helper = this.instance.options._helper, r.options.helper == "original" && this.instance.currentItem.css({
                    top: "auto",
                    left: "auto"
                })) : (this.instance.cancelHelperRemoval = !1, this.instance._trigger("deactivate", t, i))
            })
        },
        drag: function(t, n) {
            var r = e(this).data("draggable"),
            i = this,
            s = function(t) {
                var n = this.offset.click.top,
                r = this.offset.click.left,
                i = this.positionAbs.top,
                s = this.positionAbs.left,
                o = t.height,
                u = t.width,
                a = t.top,
                f = t.left;
                return e.ui.isOver(i + n, s + r, a, f, o, u)
            };
            e.each(r.sortables, 
            function(s) {
                var o = !1,
                u = this;
                this.instance.positionAbs = r.positionAbs,
                this.instance.helperProportions = r.helperProportions,
                this.instance.offset.click = r.offset.click,
                this.instance._intersectsWith(this.instance.containerCache) && (o = !0, e.each(r.sortables, 
                function() {
                    return this.instance.positionAbs = r.positionAbs,
                    this.instance.helperProportions = r.helperProportions,
                    this.instance.offset.click = r.offset.click,
                    this != u && this.instance._intersectsWith(this.instance.containerCache) && e.ui.contains(u.instance.element[0], this.instance.element[0]) && (o = !1),
                    o
                })),
                o ? (this.instance.isOver || (this.instance.isOver = 1, this.instance.currentItem = e(i).clone().removeAttr("id").appendTo(this.instance.element).data("sortable-item", !0), this.instance.options._helper = this.instance.options.helper, this.instance.options.helper = function() {
                    return n.helper[0]
                },
                t.target = this.instance.currentItem[0], this.instance._mouseCapture(t, !0), this.instance._mouseStart(t, !0, !0), this.instance.offset.click.top = r.offset.click.top, this.instance.offset.click.left = r.offset.click.left, this.instance.offset.parent.left -= r.offset.parent.left - this.instance.offset.parent.left, this.instance.offset.parent.top -= r.offset.parent.top - this.instance.offset.parent.top, r._trigger("toSortable", t), r.dropped = this.instance.element, r.currentItem = r.element, this.instance.fromOutside = r), this.instance.currentItem && this.instance._mouseDrag(t)) : this.instance.isOver && (this.instance.isOver = 0, this.instance.cancelHelperRemoval = !0, this.instance.options.revert = !1, this.instance._trigger("out", t, this.instance._uiHash(this.instance)), this.instance._mouseStop(t, !0), this.instance.options.helper = this.instance.options._helper, this.instance.currentItem.remove(), this.instance.placeholder && this.instance.placeholder.remove(), r._trigger("fromSortable", t), r.dropped = !1)
            })
        }
    }),
    e.ui.plugin.add("draggable", "cursor", {
        start: function(t, n) {
            var r = e("body"),
            i = e(this).data("draggable").options;
            r.css("cursor") && (i._cursor = r.css("cursor")),
            r.css("cursor", i.cursor)
        },
        stop: function(t, n) {
            var r = e(this).data("draggable").options;
            r._cursor && e("body").css("cursor", r._cursor)
        }
    }),
    e.ui.plugin.add("draggable", "opacity", {
        start: function(t, n) {
            var r = e(n.helper),
            i = e(this).data("draggable").options;
            r.css("opacity") && (i._opacity = r.css("opacity")),
            r.css("opacity", i.opacity)
        },
        stop: function(t, n) {
            var r = e(this).data("draggable").options;
            r._opacity && e(n.helper).css("opacity", r._opacity)
        }
    }),
    e.ui.plugin.add("draggable", "scroll", {
        start: function(t, n) {
            var r = e(this).data("draggable");
            r.scrollParent[0] != document && r.scrollParent[0].tagName != "HTML" && (r.overflowOffset = r.scrollParent.offset())
        },
        drag: function(t, n) {
            var r = e(this).data("draggable"),
            i = r.options,
            s = !1;
            if (r.scrollParent[0] != document && r.scrollParent[0].tagName != "HTML") {
                if (!i.axis || i.axis != "x") r.overflowOffset.top + r.scrollParent[0].offsetHeight - t.pageY < i.scrollSensitivity ? r.scrollParent[0].scrollTop = s = r.scrollParent[0].scrollTop + i.scrollSpeed: t.pageY - r.overflowOffset.top < i.scrollSensitivity && (r.scrollParent[0].scrollTop = s = r.scrollParent[0].scrollTop - i.scrollSpeed);
                if (!i.axis || i.axis != "y") r.overflowOffset.left + r.scrollParent[0].offsetWidth - t.pageX < i.scrollSensitivity ? r.scrollParent[0].scrollLeft = s = r.scrollParent[0].scrollLeft + i.scrollSpeed: t.pageX - r.overflowOffset.left < i.scrollSensitivity && (r.scrollParent[0].scrollLeft = s = r.scrollParent[0].scrollLeft - i.scrollSpeed)
            } else {
                if (!i.axis || i.axis != "x") t.pageY - e(document).scrollTop() < i.scrollSensitivity ? s = e(document).scrollTop(e(document).scrollTop() - i.scrollSpeed) : e(window).height() - (t.pageY - e(document).scrollTop()) < i.scrollSensitivity && (s = e(document).scrollTop(e(document).scrollTop() + i.scrollSpeed));
                if (!i.axis || i.axis != "y") t.pageX - e(document).scrollLeft() < i.scrollSensitivity ? s = e(document).scrollLeft(e(document).scrollLeft() - i.scrollSpeed) : e(window).width() - (t.pageX - e(document).scrollLeft()) < i.scrollSensitivity && (s = e(document).scrollLeft(e(document).scrollLeft() + i.scrollSpeed))
            }
            s !== !1 && e.ui.ddmanager && !i.dropBehaviour && e.ui.ddmanager.prepareOffsets(r, t)
        }
    }),
    e.ui.plugin.add("draggable", "snap", {
        start: function(t, n) {
            var r = e(this).data("draggable"),
            i = r.options;
            r.snapElements = [],
            e(i.snap.constructor != String ? i.snap.items || ":data(draggable)": i.snap).each(function() {
                var t = e(this),
                n = t.offset();
                this != r.element[0] && r.snapElements.push({
                    item: this,
                    width: t.outerWidth(),
                    height: t.outerHeight(),
                    top: n.top,
                    left: n.left
                })
            })
        },
        drag: function(t, n) {
            var r = e(this).data("draggable"),
            i = r.options,
            s = i.snapTolerance,
            o = n.offset.left,
            u = o + r.helperProportions.width,
            a = n.offset.top,
            f = a + r.helperProportions.height;
            for (var l = r.snapElements.length - 1; l >= 0; l--) {
                var c = r.snapElements[l].left,
                h = c + r.snapElements[l].width,
                p = r.snapElements[l].top,
                d = p + r.snapElements[l].height;
                if (! (c - s < o && o < h + s && p - s < a && a < d + s || c - s < o && o < h + s && p - s < f && f < d + s || c - s < u && u < h + s && p - s < a && a < d + s || c - s < u && u < h + s && p - s < f && f < d + s)) {
                    r.snapElements[l].snapping && r.options.snap.release && r.options.snap.release.call(r.element, t, e.extend(r._uiHash(), {
                        snapItem: r.snapElements[l].item
                    })),
                    r.snapElements[l].snapping = !1;
                    continue
                }
                if (i.snapMode != "inner") {
                    var v = Math.abs(p - f) <= s,
                    m = Math.abs(d - a) <= s,
                    g = Math.abs(c - u) <= s,
                    y = Math.abs(h - o) <= s;
                    v && (n.position.top = r._convertPositionTo("relative", {
                        top: p - r.helperProportions.height,
                        left: 0
                    }).top - r.margins.top),
                    m && (n.position.top = r._convertPositionTo("relative", {
                        top: d,
                        left: 0
                    }).top - r.margins.top),
                    g && (n.position.left = r._convertPositionTo("relative", {
                        top: 0,
                        left: c - r.helperProportions.width
                    }).left - r.margins.left),
                    y && (n.position.left = r._convertPositionTo("relative", {
                        top: 0,
                        left: h
                    }).left - r.margins.left)
                }
                var b = v || m || g || y;
                if (i.snapMode != "outer") {
                    var v = Math.abs(p - a) <= s,
                    m = Math.abs(d - f) <= s,
                    g = Math.abs(c - o) <= s,
                    y = Math.abs(h - u) <= s;
                    v && (n.position.top = r._convertPositionTo("relative", {
                        top: p,
                        left: 0
                    }).top - r.margins.top),
                    m && (n.position.top = r._convertPositionTo("relative", {
                        top: d - r.helperProportions.height,
                        left: 0
                    }).top - r.margins.top),
                    g && (n.position.left = r._convertPositionTo("relative", {
                        top: 0,
                        left: c
                    }).left - r.margins.left),
                    y && (n.position.left = r._convertPositionTo("relative", {
                        top: 0,
                        left: h - r.helperProportions.width
                    }).left - r.margins.left)
                } ! r.snapElements[l].snapping && (v || m || g || y || b) && r.options.snap.snap && r.options.snap.snap.call(r.element, t, e.extend(r._uiHash(), {
                    snapItem: r.snapElements[l].item
                })),
                r.snapElements[l].snapping = v || m || g || y || b
            }
        }
    }),
    e.ui.plugin.add("draggable", "stack", {
        start: function(t, n) {
            var r = e(this).data("draggable").options,
            i = e.makeArray(e(r.stack)).sort(function(t, n) {
                return (parseInt(e(t).css("zIndex"), 10) || 0) - (parseInt(e(n).css("zIndex"), 10) || 0)
            });
            if (!i.length) return;
            var s = parseInt(i[0].style.zIndex) || 0;
            e(i).each(function(e) {
                this.style.zIndex = s + e
            }),
            this[0].style.zIndex = s + i.length
        }
    }),
    e.ui.plugin.add("draggable", "zIndex", {
        start: function(t, n) {
            var r = e(n.helper),
            i = e(this).data("draggable").options;
            r.css("zIndex") && (i._zIndex = r.css("zIndex")),
            r.css("zIndex", i.zIndex)
        },
        stop: function(t, n) {
            var r = e(this).data("draggable").options;
            r._zIndex && e(n.helper).css("zIndex", r._zIndex)
        }
    })
} (jQuery),
//Droppable
function(e, t) {
    e.widget("ui.droppable", {
        version: "1.9.2",
        widgetEventPrefix: "drop",
        options: {
            accept: "*",
            activeClass: !1,
            addClasses: !0,
            greedy: !1,
            hoverClass: !1,
            scope: "default",
            tolerance: "intersect"
        },
        _create: function() {
            var t = this.options,
            n = t.accept;
            this.isover = 0,
            this.isout = 1,
            this.accept = e.isFunction(n) ? n: function(e) {
                return e.is(n)
            },
            this.proportions = {
                width: this.element[0].offsetWidth,
                height: this.element[0].offsetHeight
            },
            e.ui.ddmanager.droppables[t.scope] = e.ui.ddmanager.droppables[t.scope] || [],
            e.ui.ddmanager.droppables[t.scope].push(this),
            t.addClasses && this.element.addClass("ui-droppable")
        },
        _destroy: function() {
            var t = e.ui.ddmanager.droppables[this.options.scope];
            for (var n = 0; n < t.length; n++) t[n] == this && t.splice(n, 1);
            this.element.removeClass("ui-droppable ui-droppable-disabled")
        },
        _setOption: function(t, n) {
            t == "accept" && (this.accept = e.isFunction(n) ? n: function(e) {
                return e.is(n)
            }),
            e.Widget.prototype._setOption.apply(this, arguments)
        },
        _activate: function(t) {
            var n = e.ui.ddmanager.current;
            this.options.activeClass && this.element.addClass(this.options.activeClass),
            n && this._trigger("activate", t, this.ui(n))
        },
        _deactivate: function(t) {
            var n = e.ui.ddmanager.current;
            this.options.activeClass && this.element.removeClass(this.options.activeClass),
            n && this._trigger("deactivate", t, this.ui(n))
        },
        _over: function(t) {
            var n = e.ui.ddmanager.current;
            if (!n || (n.currentItem || n.element)[0] == this.element[0]) return;
            this.accept.call(this.element[0], n.currentItem || n.element) && (this.options.hoverClass && this.element.addClass(this.options.hoverClass), this._trigger("over", t, this.ui(n)))
        },
        _out: function(t) {
            var n = e.ui.ddmanager.current;
            if (!n || (n.currentItem || n.element)[0] == this.element[0]) return;
            this.accept.call(this.element[0], n.currentItem || n.element) && (this.options.hoverClass && this.element.removeClass(this.options.hoverClass), this._trigger("out", t, this.ui(n)))
        },
        _drop: function(t, n) {
            var r = n || e.ui.ddmanager.current;
            if (!r || (r.currentItem || r.element)[0] == this.element[0]) return ! 1;
            var i = !1;
            return this.element.find(":data(droppable)").not(".ui-draggable-dragging").each(function() {
                var t = e.data(this, "droppable");
                if (t.options.greedy && !t.options.disabled && t.options.scope == r.options.scope && t.accept.call(t.element[0], r.currentItem || r.element) && e.ui.intersect(r, e.extend(t, {
                    offset: t.element.offset()
                }), t.options.tolerance)) return i = !0,
                !1
            }),
            i ? !1: this.accept.call(this.element[0], r.currentItem || r.element) ? (this.options.activeClass && this.element.removeClass(this.options.activeClass), this.options.hoverClass && this.element.removeClass(this.options.hoverClass), this._trigger("drop", t, this.ui(r)), this.element) : !1
        },
        ui: function(e) {
            return {
                draggable: e.currentItem || e.element,
                helper: e.helper,
                position: e.position,
                offset: e.positionAbs
            }
        }
    }),
    e.ui.intersect = function(t, n, r) {
        if (!n.offset) return ! 1;
        var i = (t.positionAbs || t.position.absolute).left,
        s = i + t.helperProportions.width,
        o = (t.positionAbs || t.position.absolute).top,
        u = o + t.helperProportions.height,
        a = n.offset.left,
        f = a + n.proportions.width,
        l = n.offset.top,
        c = l + n.proportions.height;
        switch (r) {
        case "fit":
            return a <= i && s <= f && l <= o && u <= c;
        case "intersect":
            return a < i + t.helperProportions.width / 2 && s - t.helperProportions.width / 2 < f && l < o + t.helperProportions.height / 2 && u - t.helperProportions.height / 2 < c;
        case "pointer":
            var h = (t.positionAbs || t.position.absolute).left + (t.clickOffset || t.offset.click).left,
            p = (t.positionAbs || t.position.absolute).top + (t.clickOffset || t.offset.click).top,
            d = e.ui.isOver(p, h, l, a, n.proportions.height, n.proportions.width);
            return d;
        case "touch":
            return (o >= l && o <= c || u >= l && u <= c || o < l && u > c) && (i >= a && i <= f || s >= a && s <= f || i < a && s > f);
        default:
            return ! 1
        }
    },
    e.ui.ddmanager = {
        current: null,
        droppables: {
            "default": []
        },
        prepareOffsets: function(t, n) {
            var r = e.ui.ddmanager.droppables[t.options.scope] || [],
            i = n ? n.type: null,
            s = (t.currentItem || t.element).find(":data(droppable)").andSelf();
            e: for (var o = 0; o < r.length; o++) {
                if (r[o].options.disabled || t && !r[o].accept.call(r[o].element[0], t.currentItem || t.element)) continue;
                for (var u = 0; u < s.length; u++) if (s[u] == r[o].element[0]) {
                    r[o].proportions.height = 0;
                    continue e
                }
                r[o].visible = r[o].element.css("display") != "none";
                if (!r[o].visible) continue;
                i == "mousedown" && r[o]._activate.call(r[o], n),
                r[o].offset = r[o].element.offset(),
                r[o].proportions = {
                    width: r[o].element[0].offsetWidth,
                    height: r[o].element[0].offsetHeight
                }
            }
        },
        drop: function(t, n) {
            var r = !1;
            return e.each(e.ui.ddmanager.droppables[t.options.scope] || [], 
            function() {
                if (!this.options) return; ! this.options.disabled && this.visible && e.ui.intersect(t, this, this.options.tolerance) && (r = this._drop.call(this, n) || r),
                !this.options.disabled && this.visible && this.accept.call(this.element[0], t.currentItem || t.element) && (this.isout = 1, this.isover = 0, this._deactivate.call(this, n))
            }),
            r
        },
        dragStart: function(t, n) {
            t.element.parentsUntil("body").bind("scroll.droppable", 
            function() {
                t.options.refreshPositions || e.ui.ddmanager.prepareOffsets(t, n)
            })
        },
        drag: function(t, n) {
            t.options.refreshPositions && e.ui.ddmanager.prepareOffsets(t, n),
            e.each(e.ui.ddmanager.droppables[t.options.scope] || [], 
            function() {
                if (this.options.disabled || this.greedyChild || !this.visible) return;
                var r = e.ui.intersect(t, this, this.options.tolerance),
                i = !r && this.isover == 1 ? "isout": r && this.isover == 0 ? "isover": null;
                if (!i) return;
                var s;
                if (this.options.greedy
                ) {
                    var o = this.options.scope,
                    u = this.element.parents(":data(droppable)").filter(function() {
                        return e.data(this, "droppable").options.scope === o
                    });
                    u.length && (s = e.data(u[0], "droppable"), s.greedyChild = i == "isover" ? 1: 0)
                }
                s && i == "isover" && (s.isover = 0, s.isout = 1, s._out.call(s, n)),
                this[i] = 1,
                this[i == "isout" ? "isover": "isout"] = 0,
                this[i == "isover" ? "_over": "_out"].call(this, n),
                s && i == "isout" && (s.isout = 0, s.isover = 1, s._over.call(s, n))
            })
        },
        dragStop: function(t, n) {
            t.element.parentsUntil("body").unbind("scroll.droppable"),
            t.options.refreshPositions || e.ui.ddmanager.prepareOffsets(t, n)
        }
    }
} (jQuery),
//Sortable 
function(e, t) {
    e.widget("ui.sortable", e.ui.mouse, {
        version: "1.9.2",
        widgetEventPrefix: "sort",
        ready: !1,
        options: {
            appendTo: "parent",
            axis: !1,
            connectWith: !1,
            containment: !1,
            cursor: "auto",
            cursorAt: !1,
            dropOnEmpty: !0,
            forcePlaceholderSize: !1,
            forceHelperSize: !1,
            grid: !1,
            handle: !1,
            helper: "original",
            items: "> *",
            opacity: !1,
            placeholder: !1,
            revert: !1,
            scroll: !0,
            scrollSensitivity: 20,
            scrollSpeed: 20,
            scope: "default",
            tolerance: "intersect",
            zIndex: 1e3
        },
        _create: function() {
            var e = this.options;
            this.containerCache = {},
            this.element.addClass("ui-sortable"),
            this.refresh(),
            this.floating = this.items.length ? e.axis === "x" || /left|right/.test(this.items[0].item.css("float")) || /inline|table-cell/.test(this.items[0].item.css("display")) : !1,
            this.offset = this.element.offset(),
            this._mouseInit(),
            this.ready = !0
        },
        _destroy: function() {
            this.element.removeClass("ui-sortable ui-sortable-disabled"),
            this._mouseDestroy();
            for (var e = this.items.length - 1; e >= 0; e--) this.items[e].item.removeData(this.widgetName + "-item");
            return this
        },
        _setOption: function(t, n) {
            t === "disabled" ? (this.options[t] = n, this.widget().toggleClass("ui-sortable-disabled", !!n)) : e.Widget.prototype._setOption.apply(this, arguments)
        },
        _mouseCapture: function(t, n) {
            var r = this;
            if (this.reverting) return ! 1;
            if (this.options.disabled || this.options.type == "static") return ! 1;
            this._refreshItems(t);
            var i = null,
            s = e(t.target).parents().each(function() {
                if (e.data(this, r.widgetName + "-item") == r) return i = e(this),
                !1
            });
            e.data(t.target, r.widgetName + "-item") == r && (i = e(t.target));
            if (!i) return ! 1;
            if (this.options.handle && !n) {
                var o = !1;
                e(this.options.handle, i).find("*").andSelf().each(function() {
                    this == t.target && (o = !0)
                });
                if (!o) return ! 1
            }
            return this.currentItem = i,
            this._removeCurrentsFromItems(),
            !0
        },
        _mouseStart: function(t, n, r) {
            var i = this.options;
            this.currentContainer = this,
            this.refreshPositions(),
            this.helper = this._createHelper(t),
            this._cacheHelperProportions(),
            this._cacheMargins(),
            this.scrollParent = this.helper.scrollParent(),
            this.offset = this.currentItem.offset(),
            this.offset = {
                top: this.offset.top - this.margins.top,
                left: this.offset.left - this.margins.left
            },
            e.extend(this.offset, {
                click: {
                    left: t.pageX - this.offset.left,
                    top: t.pageY - this.offset.top
                },
                parent: this._getParentOffset(),
                relative: this._getRelativeOffset()
            }),
            this.helper.css("position", "absolute"),
            this.cssPosition = this.helper.css("position"),
            this.originalPosition = this._generatePosition(t),
            this.originalPageX = t.pageX,
            this.originalPageY = t.pageY,
            i.cursorAt && this._adjustOffsetFromHelper(i.cursorAt),
            this.domPosition = {
                prev: this.currentItem.prev()[0],
                parent: this.currentItem.parent()[0]
            },
            this.helper[0] != this.currentItem[0] && this.currentItem.hide(),
            this._createPlaceholder(),
            i.containment && this._setContainment(),
            i.cursor && (e("body").css("cursor") && (this._storedCursor = e("body").css("cursor")), e("body").css("cursor", i.cursor)),
            i.opacity && (this.helper.css("opacity") && (this._storedOpacity = this.helper.css("opacity")), this.helper.css("opacity", i.opacity)),
            i.zIndex && (this.helper.css("zIndex") && (this._storedZIndex = this.helper.css("zIndex")), this.helper.css("zIndex", i.zIndex)),
            this.scrollParent[0] != document && this.scrollParent[0].tagName != "HTML" && (this.overflowOffset = this.scrollParent.offset()),
            this._trigger("start", t, this._uiHash()),
            this._preserveHelperProportions || this._cacheHelperProportions();
            if (!r) for (var s = this.containers.length - 1; s >= 0; s--) this.containers[s]._trigger("activate", t, this._uiHash(this));
            return e.ui.ddmanager && (e.ui.ddmanager.current = this),
            e.ui.ddmanager && !i.dropBehaviour && e.ui.ddmanager.prepareOffsets(this, t),
            this.dragging = !0,
            this.helper.addClass("ui-sortable-helper"),
            this._mouseDrag(t),
            !0
        },
        _mouseDrag: function(t) {
            this.position = this._generatePosition(t),
            this.positionAbs = this._convertPositionTo("absolute"),
            this.lastPositionAbs || (this.lastPositionAbs = this.positionAbs);
            if (this.options.scroll) {
                var n = this.options,
                r = !1;
                this.scrollParent[0] != document && this.scrollParent[0].tagName != "HTML" ? (this.overflowOffset.top + this.scrollParent[0].offsetHeight - t.pageY < n.scrollSensitivity ? this.scrollParent[0].scrollTop = r = this.scrollParent[0].scrollTop + n.scrollSpeed: t.pageY - this.overflowOffset.top < n.scrollSensitivity && (this.scrollParent[0].scrollTop = r = this.scrollParent[0].scrollTop - n.scrollSpeed), this.overflowOffset.left + this.scrollParent[0].offsetWidth - t.pageX < n.scrollSensitivity ? this.scrollParent[0].scrollLeft = r = this.scrollParent[0].scrollLeft + n.scrollSpeed: t.pageX - this.overflowOffset.left < n.scrollSensitivity && (this.scrollParent[0].scrollLeft = r = this.scrollParent[0].scrollLeft - n.scrollSpeed)) : (t.pageY - e(document).scrollTop() < n.scrollSensitivity ? r = e(document).scrollTop(e(document).scrollTop() - n.scrollSpeed) : e(window).height() - (t.pageY - e(document).scrollTop()) < n.scrollSensitivity && (r = e(document).scrollTop(e(document).scrollTop() + n.scrollSpeed)), t.pageX - e(document).scrollLeft() < n.scrollSensitivity ? r = e(document).scrollLeft(e(document).scrollLeft() - n.scrollSpeed) : e(window).width() - (t.pageX - e(document).scrollLeft()) < n.scrollSensitivity && (r = e(document).scrollLeft(e(document).scrollLeft() + n.scrollSpeed))),
                r !== !1 && e.ui.ddmanager && !n.dropBehaviour && e.ui.ddmanager.prepareOffsets(this, t)
            }
            this.positionAbs = this._convertPositionTo("absolute");
            if (!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left + "px";
            if (!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top + "px";
            for (var i = this.items.length - 1; i >= 0; i--) {
                var s = this.items[i],
                o = s.item[0],
                u = this._intersectsWithPointer(s);
                if (!u) continue;
                if (s.instance !== this.currentContainer) continue;
                if (o != this.currentItem[0] && this.placeholder[u == 1 ? "next": "prev"]()[0] != o && !e.contains(this.placeholder[0], o) && (this.options.type == "semi-dynamic" ? !e.contains(this.element[0], o) : !0)) {
                    this.direction = u == 1 ? "down": "up";
                    if (this.options.tolerance != "pointer" && !this._intersectsWithSides(s)) break;
                    this._rearrange(t, s),
                    this._trigger("change", t, this._uiHash());
                    break
                }
            }
            return this._contactContainers(t),
            e.ui.ddmanager && e.ui.ddmanager.drag(this, t),
            this._trigger("sort", t, this._uiHash()),
            this.lastPositionAbs = this.positionAbs,
            !1
        },
        _mouseStop: function(t, n) {
            if (!t) return;
            e.ui.ddmanager && !this.options.dropBehaviour && e.ui.ddmanager.drop(this, t);
            if (this.options.revert) {
                var r = this,
                i = this.placeholder.offset();
                this.reverting = !0,
                e(this.helper).animate({
                    left: i.left - this.offset.parent.left - this.margins.left + (this.offsetParent[0] == document.body ? 0: this.offsetParent[0].scrollLeft),
                    top: i.top - this.offset.parent.top - this.margins.top + (this.offsetParent[0] == document.body ? 0: this.offsetParent[0].scrollTop)
                },
                parseInt(this.options.revert, 10) || 500, 
                function() {
                    r._clear(t)
                })
            } else this._clear(t, n);
            return ! 1
        },
        cancel: function() {
            if (this.dragging) {
                this._mouseUp({
                    target: null
                }),
                this.options.helper == "original" ? this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper") : this.currentItem.show();
                for (var t = this.containers.length - 1; t >= 0; t--) this.containers[t]._trigger("deactivate", null, this._uiHash(this)),
                this.containers[t].containerCache.over && (this.containers[t]._trigger("out", null, this._uiHash(this)), this.containers[t].containerCache.over = 0)
            }
            return this.placeholder && (this.placeholder[0].parentNode && this.placeholder[0].parentNode.removeChild(this.placeholder[0]), this.options.helper != "original" && this.helper && this.helper[0].parentNode && this.helper.remove(), e.extend(this, {
                helper: null,
                dragging: !1,
                reverting: !1,
                _noFinalSort: null
            }), this.domPosition.prev ? e(this.domPosition.prev).after(this.currentItem) : e(this.domPosition.parent).prepend(this.currentItem)),
            this
        },
        serialize: function(t) {
            var n = this._getItemsAsjQuery(t && t.connected),
            r = [];
            return t = t || {},
            e(n).each(function() {
                var n = (e(t.item || this).attr(t.attribute || "id") || "").match(t.expression || /(.+)[-=_](.+)/);
                n && r.push((t.key || n[1] + "[]") + "=" + (t.key && t.expression ? n[1] : n[2]))
            }),
            !r.length && t.key && r.push(t.key + "="),
            r.join("&")
        },
        toArray: function(t) {
            var n = this._getItemsAsjQuery(t && t.connected),
            r = [];
            return t = t || {},
            n.each(function() {
                r.push(e(t.item || this).attr(t.attribute || "id") || "")
            }),
            r
        },
        _intersectsWith: function(e) {
            var t = this.positionAbs.left,
            n = t + this.helperProportions.width,
            r = this.positionAbs.top,
            i = r + this.helperProportions.height,
            s = e.left,
            o = s + e.width,
            u = e.top,
            a = u + e.height,
            f = this.offset.click.top,
            l = this.offset.click.left,
            c = r + f > u && r + f < a && t + l > s && t + l < o;
            return this.options.tolerance == "pointer" || this.options.forcePointerForContainers || this.options.tolerance != "pointer" && this.helperProportions[this.floating ? "width": "height"] > e[this.floating ? "width": "height"] ? c: s < t + this.helperProportions.width / 2 && n - this.helperProportions.width / 2 < o && u < r + this.helperProportions.height / 2 && i - this.helperProportions.height / 2 < a
        },
        _intersectsWithPointer: function(t) {
            var n = this.options.axis === "x" || e.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, t.top, t.height),
            r = this.options.axis === "y" || e.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, t.left, t.width),
            i = n && r,
            s = this._getDragVerticalDirection(),
            o = this._getDragHorizontalDirection();
            return i ? this.floating ? o && o == "right" || s == "down" ? 2: 1: s && (s == "down" ? 2: 1) : !1
        },
        _intersectsWithSides: function(t) {
            var n = e.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, t.top + t.height / 2, t.height),
            r = e.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, t.left + t.width / 2, t.width),
            i = this._getDragVerticalDirection(),
            s = this._getDragHorizontalDirection();
            return this.floating && s ? s == "right" && r || s == "left" && !r: i && (i == "down" && n || i == "up" && !n)
        },
        _getDragVerticalDirection: function() {
            var e = this.positionAbs.top - this.lastPositionAbs.top;
            return e != 0 && (e > 0 ? "down": "up")
        },
        _getDragHorizontalDirection: function() {
            var e = this.positionAbs.left - this.lastPositionAbs.left;
            return e != 0 && (e > 0 ? "right": "left")
        },
        refresh: function(e) {
            return this._refreshItems(e),
            this.refreshPositions(),
            this
        },
        _connectWith: function() {
            var e = this.options;
            return e.connectWith.constructor == String ? [e.connectWith] : e.connectWith
        },
        _getItemsAsjQuery: function(t) {
            var n = [],
            r = [],
            i = this._connectWith();
            if (i && t) for (var s = i.length - 1; s >= 0; s--) {
                var o = e(i[s]);
                for (var u = o.length - 1; u >= 0; u--) {
                    var a = e.data(o[u], this.widgetName);
                    a && a != this && !a.options.disabled && r.push([e.isFunction(a.options.items) ? a.options.items.call(a.element) : e(a.options.items, a.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"), a])
                }
            }
            r.push([e.isFunction(this.options.items) ? this.options.items.call(this.element, null, {
                options: this.options,
                item: this.currentItem
            }) : e(this.options.items, this.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"), this]);
            for (var s = r.length - 1; s >= 0; s--) r[s][0].each(function() {
                n.push(this)
            });
            return e(n)
        },
        _removeCurrentsFromItems: function() {
            var t = this.currentItem.find(":data(" + this.widgetName + "-item)");
            this.items = e.grep(this.items, 
            function(e) {
                for (var n = 0; n < t.length; n++) if (t[n] == e.item[0]) return ! 1;
                return ! 0
            })
        },
        _refreshItems: function(t) {
            this.items = [],
            this.containers = [this];
            var n = this.items,
            r = [[e.isFunction(this.options.items) ? this.options.items.call(this.element[0], t, {
                item: this.currentItem
            }) : e(this.options.items, this.element), this]],
            i = this._connectWith();
            if (i && this.ready) for (var s = i.length - 1; s >= 0; s--) {
                var o = e(i[s]);
                for (var u = o.length - 1; u >= 0; u--) {
                    var a = e.data(o[u], this.widgetName);
                    a && a != this && !a.options.disabled && (r.push([e.isFunction(a.options.items) ? a.options.items.call(a.element[0], t, {
                        item: this.currentItem
                    }) : e(a.options.items, a.element), a]), this.containers.push(a))
                }
            }
            for (var s = r.length - 1; s >= 0; s--) {
                var f = r[s][1],
                l = r[s][0];
                for (var u = 0, c = l.length; u < c; u++) {
                    var h = e(l[u]);
                    h.data(this.widgetName + "-item", f),
                    n.push({
                        item: h,
                        instance: f,
                        width: 0,
                        height: 0,
                        left: 0,
                        top: 0
                    })
                }
            }
        },
        refreshPositions: function(t) {
            this.offsetParent && this.helper && (this.offset.parent = this._getParentOffset());
            for (var n = this.items.length - 1; n >= 0; n--) {
                var r = this.items[n];
                if (r.instance != this.currentContainer && this.currentContainer && r.item[0] != this.currentItem[0]) continue;
                var i = this.options.toleranceElement ? e(this.options.toleranceElement, r.item) : r.item;
                t || (r.width = i.outerWidth(), r.height = i.outerHeight());
                var s = i.offset();
                r.left = s.left,
                r.top = s.top
            }
            if (this.options.custom && this.options.custom.refreshContainers) this.options.custom.refreshContainers.call(this);
            else for (var n = this.containers.length - 1; n >= 0; n--) {
                var s = this.containers[n].element.offset();
                this.containers[n].containerCache.left = s.left,
                this.containers[n].containerCache.top = s.top,
                this.containers[n].containerCache.width = this.containers[n].element.outerWidth(),
                this.containers[n].containerCache.height = this.containers[n].element.outerHeight()
            }
            return this
        },
        _createPlaceholder: function(t) {
            t = t || this;
            var n = t.options;
            if (!n.placeholder || n.placeholder.constructor == String) {
                var r = n.placeholder;
                n.placeholder = {
                    element: function() {
                        var n = e(document.createElement(t.currentItem[0].nodeName)).addClass(r || t.currentItem[0].className + " ui-sortable-placeholder").removeClass("ui-sortable-helper")[0];
                        return r || (n.style.visibility = "hidden"),
                        n
                    },
                    update: function(e, i) {
                        if (r && !n.forcePlaceholderSize) return;
                        i.height() || i.height(t.currentItem.innerHeight() - parseInt(t.currentItem.css("paddingTop") || 0, 10) - parseInt(t.currentItem.css("paddingBottom") || 0, 10)),
                        i.width() || i.width(t.currentItem.innerWidth() - parseInt(t.currentItem.css("paddingLeft") || 0, 10) - parseInt(t.currentItem.css("paddingRight") || 0, 10))
                    }
                }
            }
            t.placeholder = e(n.placeholder.element.call(t.element, t.currentItem)),
            t.currentItem.after(t.placeholder),
            n.placeholder.update(t, t.placeholder)
        },
        _contactContainers: function(t) {
            var n = null,
            r = null;
            for (var i = this.containers.length - 1; i >= 0; i--) {
                if (e.contains(this.currentItem[0], this.containers[i].element[0])) continue;
                if (this._intersectsWith(this.containers[i].containerCache)) {
                    if (n && e.contains(this.containers[i].element[0], n.element[0])) continue;
                    n = this.containers[i],
                    r = i
                } else this.containers[i].containerCache.over && (this.containers[i]._trigger("out", t, this._uiHash(this)), this.containers[i].containerCache.over = 0)
            }
            if (!n) return;
            if (this.containers.length === 1) this.containers[r]._trigger("over", t, this._uiHash(this)),
            this.containers[r].containerCache.over = 1;
            else {
                var s = 1e4,
                o = null,
                u = this.containers[r].floating ? "left": "top",
                a = this.containers[r].floating ? "width": "height",
                f = this.positionAbs[u] + this.offset.click[u];
                for (var l = this.items.length - 1; l >= 0; l--) {
                    if (!e.contains(this.containers[r].element[0], this.items[l].item[0])) continue;
                    if (this.items[l].item[0] == this.currentItem[0]) continue;
                    var c = this.items[l].item.offset()[u],
                    h = !1;
                    Math.abs(c - f) > Math.abs(c + this.items[l][a] - f) && (h = !0, c += this.items[l][a]),
                    Math.abs(c - f) < s && (s = Math.abs(c - f), o = this.items[l], this.direction = h ? "up": "down")
                }
                if (!o && !this.options.dropOnEmpty) return;
                this.currentContainer = this.containers[r],
                o ? this._rearrange(t, o, null, !0) : this._rearrange(t, null, this.containers[r].element, !0),
                this._trigger("change", t, this._uiHash()),
                this.containers[r]._trigger("change", t, this._uiHash(this)),
                this.options.placeholder.update(this.currentContainer, this.placeholder),
                this.containers[r]._trigger("over", t, this._uiHash(this)),
                this.containers[r].containerCache.over = 1
            }
        },
        _createHelper: function(t) {
            var n = this.options,
            r = e.isFunction(n.helper) ? e(n.helper.apply(this.element[0], [t, this.currentItem])) : n.helper == "clone" ? this.currentItem.clone() : this.currentItem;
            return r.parents("body").length || e(n.appendTo != "parent" ? n.appendTo: this.currentItem[0].parentNode)[0].appendChild(r[0]),
            r[0] == this.currentItem[0] && (this._storedCSS = {
                width: this.currentItem[0].style.width,
                height: this.currentItem[0].style.height,
                position: this.currentItem.css("position"),
                top: this.currentItem.css("top"),
                left: this.currentItem.css("left")
            }),
            (r[0].style.width == "" || n.forceHelperSize) && r.width(this.currentItem.width()),
            (r[0].style.height == "" || n.forceHelperSize) && r.height(this.currentItem.height()),
            r
        },
        _adjustOffsetFromHelper: function(t) {
            typeof t == "string" && (t = t.split(" ")),
            e.isArray(t) && (t = {
                left: +t[0],
                top: +t[1] || 0
            }),
            "left" in t && (this.offset.click.left = t.left + this.margins.left),
            "right" in t && (this.offset.click.left = this.helperProportions.width - t.right + this.margins.left),
            "top" in t && (this.offset.click.top = t.top + this.margins.top),
            "bottom" in t && (this.offset.click.top = this.helperProportions.height - t.bottom + this.margins.top)
        },
        _getParentOffset: function() {
            this.offsetParent = this.helper.offsetParent();
            var t = this.offsetParent.offset();
            this.cssPosition == "absolute" && this.scrollParent[0] != document && e.contains(this.scrollParent[0], this.offsetParent[0]) && (t.left += this.scrollParent.scrollLeft(), t.top += this.scrollParent.scrollTop());
            if (this.offsetParent[0] == document.body || this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == "html" && e.ui.ie) t = {
                top: 0,
                left: 0
            };
            return {
                top: t.top + (parseInt(this.offsetParent.css("borderTopWidth"), 10) || 0),
                left: t.left + (parseInt(this.offsetParent.css("borderLeftWidth"), 10) || 0)
            }
        },
        _getRelativeOffset: function() {
            if (this.cssPosition == "relative") {
                var e = this.currentItem.position();
                return {
                    top: e.top - (parseInt(this.helper.css("top"), 10) || 0) + this.scrollParent.scrollTop(),
                    left: e.left - (parseInt(this.helper.css("left"), 10) || 0) + this.scrollParent.scrollLeft()
                }
            }
            return {
                top: 0,
                left: 0
            }
        },
        _cacheMargins: function() {
            this.margins = {
                left: parseInt(this.currentItem.css("marginLeft"), 10) || 0,
                top: parseInt(this.currentItem.css("marginTop"), 10) || 0
            }
        },
        _cacheHelperProportions: function() {
            this.helperProportions = {
                width: this.helper.outerWidth(),
                height: this.helper.outerHeight()
            }
        },
        _setContainment: function() {
            var t = this.options;
            t.containment == "parent" && (t.containment = this.helper[0].parentNode);
            if (t.containment == "document" || t.containment == "window") this.containment = [0 - this.offset.relative.left - this.offset.parent.left, 0 - this.offset.relative.top - this.offset.parent.top, e(t.containment == "document" ? document: window).width() - this.helperProportions.width - this.margins.left, (e(t.containment == "document" ? document: window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top];
            if (!/^(document|window|parent)$/.test(t.containment)) {
                var n = e(t.containment)[0],
                r = e(t.containment).offset(),
                i = e(n).css("overflow") != "hidden";
                this.containment = [r.left + (parseInt(e(n).css("borderLeftWidth"), 10) || 0) + (parseInt(e(n).css("paddingLeft"), 10) || 0) - this.margins.left, r.top + (parseInt(e(n).css("borderTopWidth"), 10) || 0) + (parseInt(e(n).css("paddingTop"), 10) || 0) - this.margins.top, r.left + (i ? Math.max(n.scrollWidth, n.offsetWidth) : n.offsetWidth) - (parseInt(e(n).css("borderLeftWidth"), 10) || 0) - (parseInt(e(n).css("paddingRight"), 10) || 0) - this.helperProportions.width - this.margins.left, r.top + (i ? Math.max(n.scrollHeight, n.offsetHeight) : n.offsetHeight) - (parseInt(e(n).css("borderTopWidth"), 10) || 0) - (parseInt(e(n).css("paddingBottom"), 10) || 0) - this.helperProportions.height - this.margins.top]
            }
        },
        _convertPositionTo: function(t, n) {
            n || (n = this.position);
            var r = t == "absolute" ? 1: -1,
            i = this.options,
            s = this.cssPosition != "absolute" || this.scrollParent[0] != document && !!e.contains(this.scrollParent[0], this.offsetParent[0]) ? this.scrollParent: this.offsetParent,
            o = /(html|body)/i.test(s[0].tagName);
            return {
                top: n.top + this.offset.relative.top * r + this.offset.parent.top * r - (this.cssPosition == "fixed" ? -this.scrollParent.scrollTop() : o ? 0: s.scrollTop()) * r,
                left: n.left + this.offset.relative.left * r + this.offset.parent.left * r - (this.cssPosition == "fixed" ? -this.scrollParent.scrollLeft() : o ? 0: s.scrollLeft()) * r
            }
        },
        _generatePosition: function(t) {
            var n = this.options,
            r = this.cssPosition != "absolute" || this.scrollParent[0] != document && !!e.contains(this.scrollParent[0], this.offsetParent[0]) ? this.scrollParent: this.offsetParent,
            i = /(html|body)/i.test(r[0].tagName);
            this.cssPosition == "relative" && (this.scrollParent[0] == document || this.scrollParent[0] == this.offsetParent[0]) && (this.offset.relative = this._getRelativeOffset());
            var s = t.pageX,
            o = t.pageY;
            if (this.originalPosition) {
                this.containment && (t.pageX - this.offset.click.left < this.containment[0] && (s = this.containment[0] + this.offset.click.left), t.pageY - this.offset.click.top < this.containment[1] && (o = this.containment[1] + this.offset.click.top), t.pageX - this.offset.click.left > this.containment[2] && (s = this.containment[2] + this.offset.click.left), t.pageY - this.offset.click.top > this.containment[3] && (o = this.containment[3] + this.offset.click.top));
                if (n.grid) {
                    var u = this.originalPageY + Math.round((o - this.originalPageY) / n.grid[1]) * n.grid[1];
                    o = this.containment ? u - this.offset.click.top < this.containment[1] || u - this.offset.click.top > this.containment[3] ? u - this.offset.click.top < this.containment[1] ? u + n.grid[1] : u - n.grid[1] : u: u;
                    var a = this.originalPageX + Math.round((s - this.originalPageX) / n.grid[0]) * n.grid[0];
                    s = this.containment ? a - this.offset.click.left < this.containment[0] || a - this.offset.click.left > this.containment[2] ? a - this.offset.click.left < this.containment[0] ? a + n.grid[0] : a - n.grid[0] : a: a
                }
            }
            return {
                top: o - this.offset.click.top - this.offset.relative.top - this.offset.parent.top + (this.cssPosition == "fixed" ? -this.scrollParent.scrollTop() : i ? 0: r.scrollTop()),
                left: s - this.offset.click.left - this.offset.relative.left - this.offset.parent.left + (this.cssPosition == "fixed" ? -this.scrollParent.scrollLeft() : i ? 0: r.scrollLeft())
            }
        },
        _rearrange: function(e, t, n, r) {
            n ? n[0].appendChild(this.placeholder[0]) : t.item[0].parentNode.insertBefore(this.placeholder[0], this.direction == "down" ? t.item[0] : t.item[0].nextSibling),
            this.counter = this.counter ? ++this.counter: 1;
            var i = this.counter;
            this._delay(function() {
                i == this.counter && this.refreshPositions(!r)
            })
        },
        _clear: function(t, n) {
            this.reverting = !1;
            var r = []; ! this._noFinalSort && this.currentItem.parent().length && this.placeholder.before(this.currentItem),
            this._noFinalSort = null;
            if (this.helper[0] == this.currentItem[0]) {
                for (var i in this._storedCSS) if (this._storedCSS[i] == "auto" || this._storedCSS[i] == "static") this._storedCSS[i] = "";
                this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper")
            } else this.currentItem.show();
            this.fromOutside && !n && r.push(function(e) {
                this._trigger("receive", e, this._uiHash(this.fromOutside))
            }),
            (this.fromOutside || this.domPosition.prev != this.currentItem.prev().not(".ui-sortable-helper")[0] || this.domPosition.parent != this.currentItem.parent()[0]) && !n && r.push(function(e) {
                this._trigger("update", e, this._uiHash())
            }),
            this !== this.currentContainer && (n || (r.push(function(e) {
                this._trigger("remove", e, this._uiHash())
            }), r.push(function(e) {
                return function(t) {
                    e._trigger("receive", t, this._uiHash(this))
                }
            }.call(this, this.currentContainer)), r.push(function(e) {
                return function(t) {
                    e._trigger("update", t, this._uiHash(this))
                }
            }.call(this, this.currentContainer))));
            for (var i = this.containers.length - 1; i >= 0; i--) n || r.push(function(e) {
                return function(t) {
                    e._trigger("deactivate", t, this._uiHash(this))
                }
            }.call(this, this.containers[i])),
            this.containers[i].containerCache.over && (r.push(function(e) {
                return function(t) {
                    e._trigger("out", t, this._uiHash(this))
                }
            }.call(this, this.containers[i])), this.containers[i].containerCache.over = 0);
            this._storedCursor && e("body").css("cursor", this._storedCursor),
            this._storedOpacity && this.helper.css("opacity", this._storedOpacity),
            this._storedZIndex && this.helper.css("zIndex", this._storedZIndex == "auto" ? "": this._storedZIndex),
            this.dragging = !1;
            if (this.cancelHelperRemoval) {
                if (!n) {
                    this._trigger("beforeStop", t, this._uiHash());
                    for (var i = 0; i < r.length; i++) r[i].call(this, t);
                    this._trigger("stop", t, this._uiHash())
                }
                return this.fromOutside = !1,
                !1
            }
            n || this._trigger("beforeStop", t, this._uiHash()),
            this.placeholder[0].parentNode.removeChild(this.placeholder[0]),
            this.helper[0] != this.currentItem[0] && this.helper.remove(),
            this.helper = null;
            if (!n) {
                for (var i = 0; i < r.length; i++) r[i].call(this, t);
                this._trigger("stop", t, this._uiHash())
            }
            return this.fromOutside = !1,
            !0
        },
        _trigger: function() {
            e.Widget.prototype._trigger.apply(this, arguments) === !1 && this.cancel()
        },
        _uiHash: function(t) {
            var n = t || this;
            return {
                helper: n.helper,
                placeholder: n.placeholder || e([]),
                position: n.position,
                originalPosition: n.originalPosition,
                offset: n.positionAbs,
                item: n.currentItem,
                sender: t ? t.element: null
            }
        }
    })
} (jQuery),
//json
function($) {
    var escapeable = /["\\\x00-\x1f\x7f-\x9f]/g,
    meta = {
        "\b": "\\b",
        "	": "\\t",
        "\n": "\\n",
        "\f": "\\f",
        "\r": "\\r",
        '"': '\\"',
        "\\": "\\\\"
    };
    $.toJSON = typeof JSON == "object" && JSON.stringify ? JSON.stringify: function(e) {
        if (e === null) return "null";
        var t = typeof e;
        if (t === "undefined") return undefined;
        if (t === "number" || t === "boolean") return "" + e;
        if (t === "string") return $.quoteString(e);
        if (t === "object") {
            if (typeof e.toJSON == "function") return $.toJSON(e.toJSON());
            if (e.constructor === Date) {
                var n = e.getUTCMonth() + 1,
                r = e.getUTCDate(),
                i = e.getUTCFullYear(),
                s = e.getUTCHours(),
                o = e.getUTCMinutes(),
                u = e.getUTCSeconds(),
                a = e.getUTCMilliseconds();
                return n < 10 && (n = "0" + n),
                r < 10 && (r = "0" + r),
                s < 10 && (s = "0" + s),
                o < 10 && (o = "0" + o),
                u < 10 && (u = "0" + u),
                a < 100 && (a = "0" + a),
                a < 10 && (a = "0" + a),
                '"' + i + "-" + n + "-" + r + "T" + s + ":" + o + ":" + u + "." + a + 'Z"'
            }
            if (e.constructor === Array) {
                var f = [];
                for (var l = 0; l < e.length; l++) f.push($.toJSON(e[l]) || "null");
                return "[" + f.join(",") + "]"
            }
            var c,
            h,
            p = [];
            for (var d in e) {
                t = typeof d;
                if (t === "number") c = '"' + d + '"';
                else {
                    if (t !== "string") continue;
                    c = $.quoteString(d)
                }
                t = typeof e[d];
                if (t === "function" || t === "undefined") continue;
                h = $.toJSON(e[d]),
                p.push(c + ":" + h)
            }
            return "{" + p.join(",") + "}"
        }
    },
    $.evalJSON = typeof JSON == "object" && JSON.parse ? JSON.parse: function(src) {
        return eval("(" + src + ")")
    },
    $.secureEvalJSON = typeof JSON == "object" && JSON.parse ? JSON.parse: function(src) {
        var filtered = src.replace(/\\["\\\/bfnrtu]/g, "@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]").replace(/(?:^|:|,)(?:\s*\[)+/g, "");
        if (/^[\],:{}\s]*$/.test(filtered)) return eval("(" + src + ")");
        throw new SyntaxError("Error parsing JSON, source is not valid.")
    },
    $.quoteString = function(e) {
        return e.match(escapeable) ? '"' + e.replace(escapeable, 
        function(e) {
            var t = meta[e];
            return typeof t == "string" ? t: (t = e.charCodeAt(), "\\u00" + Math.floor(t / 16).toString(16) + (t % 16).toString(16))
        }) + '"': '"' + e + '"'
    }
} (jQuery),
//rails ujs
function(e, t) {
    var n = function() {
        var t = e._data(document, "events");
        return t && t.click && e.grep(t.click, 
        function(e) {
            return e.namespace === "rails"
        }).length
    };
    n() && e.error("jquery-ujs has already been loaded!");
    var r;
    e.rails = r = {
        linkClickSelector: "a[data-confirm], a[data-method], a[data-remote], a[data-disable-with]",
        inputChangeSelector: "select[data-remote], input[data-remote], textarea[data-remote]",
        formSubmitSelector: "form",
        formInputClickSelector: "form input[type=submit], form input[type=image], form button[type=submit], form button:not([type])",
        disableSelector: "input[data-disable-with], button[data-disable-with], textarea[data-disable-with]",
        enableSelector: "input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled",
        requiredInputSelector: "input[name][required]:not([disabled]),textarea[name][required]:not([disabled])",
        fileInputSelector: "input:file",
        linkDisableSelector: "a[data-disable-with]",
        CSRFProtection: function(t) {
            var n = e('meta[name="csrf-token"]').attr("content");
            n && t.setRequestHeader("X-CSRF-Token", n)
        },
        fire: function(t, n, r) {
            var i = e.Event(n);
            return t.trigger(i, r),
            i.result !== !1
        },
        confirm: function(e) {
            return confirm(e)
        },
        ajax: function(t) {
            return e.ajax(t)
        },
        href: function(e) {
            return e.attr("href")
        },
        handleRemote: function(n) {
            var i,
            s,
            o,
            u,
            a,
            f,
            l,
            c;
            if (r.fire(n, "ajax:before")) {
                u = n.data("cross-domain"),
                a = u === t ? null: u,
                f = n.data("with-credentials") || null,
                l = n.data("type") || e.ajaxSettings && e.ajaxSettings.dataType;
                if (n.is("form")) {
                    i = n.attr("method"),
                    s = n.attr("action"),
                    o = n.serializeArray(),
                    e.each(e.ajaxSettings.data, 
                    function(e, t) {
                        o.push({
                            name: e,
                            value: t
                        })
                    });
                    var h = n.data("ujs:submit-button");
                    h && (o.push(h), n.data("ujs:submit-button", null))
                } else n.is(r.inputChangeSelector) ? (i = n.data("method"), s = n.data("url"), o = n.serializeArray(), e.each(e.ajaxSettings.data, 
                function(e, t) {
                    o.push({
                        name: e,
                        value: t
                    })
                }), n.data("params") && e.each(mcw.parseParams(n.data("params")), 
                function(e, t) {
                    o.push({
                        name: e,
                        value: t
                    })
                })) : (i = n.data("method"), s = r.href(n), o = mcw.parseParams(n.data("params")) || {});
                c = {
                    type: i || "GET",
                    data: o,
                    dataType: l,
                    beforeSend: function(e, i) {
                        return i.dataType === t && e.setRequestHeader("accept", "*/*;q=0.5, " + i.accepts.script),
                        r.fire(n, "ajax:beforeSend", [e, i])
                    },
                    success: function(e, t, r) {
                        n.trigger("ajax:success", [e, t, r])
                    },
                    complete: function(e, t) {
                        n.trigger("ajax:complete", [e, t])
                    },
                    error: function(e, t, r) {
                        n.trigger("ajax:error", [e, t, r])
                    },
                    xhrFields: {
                        withCredentials: f
                    },
                    crossDomain: a
                },
                s && (c.url = s);
                var p = r.ajax(c);
                return n.trigger("ajax:send", p),
                p
            }
            return ! 1
        },
        handleMethod: function(n) {
            var i = r.href(n),
            s = n.data("method"),
            o = n.attr("target"),
            u = e("meta[name=csrf-token]").attr("content"),
            a = e("meta[name=csrf-param]").attr("content"),
            f = e('<form method="post" action="' + i + '"></form>'),
            l = '<input name="_method" value="' + s + '" type="hidden" />';
            a !== t && u !== t && (l += '<input name="' + a + '" value="' + u + '" type="hidden" />'),
            o && f.attr("target", o),
            f.hide().append(l).appendTo("body"),
            f.submit()
        },
        disableFormElements: function(t) {
            t.find(r.disableSelector).each(function() {
                var t = e(this),
                n = t.is("button") ? "html": "val";
                t.data("ujs:enable-with", t[n]()),
                t[n](t.data("disable-with")),
                t.prop("disabled", !0)
            })
        },
        enableFormElements: function(t) {
            t.find(r.enableSelector).each(function() {
                var t = e(this),
                n = t.is("button") ? "html": "val";
                t.data("ujs:enable-with") && t[n](t.data("ujs:enable-with")),
                t.prop("disabled", !1)
            })
        },
        allowAction: function(e, t) {
            var n = e.data("confirm"),
            i = !1,
            t;
            return n ? (r.fire(e, "confirm", [t]) && mcw.confirm({
                msg: n.replace("\\n", "<br>"),
                callback: function(n, s) {
                    if (!n) return;
                    r.fire(e, "confirm:complete", [i]) && t()
                }
            }), !1) : !0
        },
        blankInputs: function(t, n, r) {
            var i = e(),
            s,
            o,
            u = n || "input,textarea",
            a = t.find(u);
            return a.each(function() {
                s = e(this),
                o = s.is(":checkbox,:radio") ? s.is(":checked") : s.val();
                if (!o == !r) {
                    if (s.is(":radio") && a.filter('input:radio:checked[name="' + s.attr("name") + '"]').length) return ! 0;
                    i = i.add(s)
                }
            }),
            i.length ? i: !1
        },
        nonBlankInputs: function(e, t) {
            return r.blankInputs(e, t, !0)
        },
        stopEverything: function(t) {
            return e(t.target).trigger("ujs:everythingStopped"),
            t.stopImmediatePropagation(),
            !1
        },
        callFormSubmitBindings: function(n, r) {
            var i = n.data("events"),
            s = !0;
            return i !== t && i.submit !== t && e.each(i.submit, 
            function(e, t) {
                if (typeof t.handler == "function") return s = t.handler(r)
            }),
            s
        },
        disableElement: function(e) {
            e.data("ujs:enable-with", e.html()),
            e.html(e.data("disable-with")),
            e.bind("click.railsDisable", 
            function(e) {
                return r.stopEverything(e)
            })
        },
        enableElement: function(e) {
            e.data("ujs:enable-with") !== t && (e.html(e.data("ujs:enable-with")), e.data("ujs:enable-with", !1)),
            e.unbind("click.railsDisable")
        }
    },
    r.fire(e(document), "rails:attachBindings") && (e.ajaxPrefilter(function(e, t, n) {
        e.crossDomain || r.CSRFProtection(n)
    }), e(document).delegate(r.linkDisableSelector, "ajax:complete", 
    function() {
        r.enableElement(e(this))
    }), e(document).delegate(r.linkClickSelector, "click.rails", 
    function(n) {
        function u() {
            i.is(r.linkDisableSelector) && r.disableElement(i);
            if (i.data("remote") !== t) {
                if ((n.metaKey || n.ctrlKey) && (!s || s === "GET") && !o) return ! 0;
                var e = r.handleRemote(i);
                return e === !1 ? r.enableElement(i) : e.error(function() {
                    r.enableElement(i)
                }),
                !1
            }
            if (i.data("method")) return r.handleMethod(i),
            !1
        }
        var i = e(this),
        s = i.data("method"),
        o = i.data("params");
        return r.allowAction(i, u) ? u() : r.stopEverything(n)
    }), e(document).delegate(r.inputChangeSelector, "change.rails", 
    function(t) {
        function i() {
            return r.handleRemote(n),
            !1
        }
        var n = e(this);
        return r.allowAction(n, i) ? i() : r.stopEverything(t)
    }), e(document).delegate(r.formSubmitSelector, "submit.rails", 
    function(n) {
        function a() {
            if (o && i.attr("novalidate") == t && r.fire(i, "ajax:aborted:required", [o])) return r.stopEverything(n);
            if (s) {
                if (u) {
                    setTimeout(function() {
                        r.disableFormElements(i)
                    },
                    13);
                    var a = r.fire(i, "ajax:aborted:file", [u]);
                    return a || setTimeout(function() {
                        r.enableFormElements(i)
                    },
                    13),
                    a
                }
                return ! e.support.submitBubbles && e().jquery < "1.7" && r.callFormSubmitBindings(i, n) === !1 ? r.stopEverything(n) : (r.handleRemote(i), !1)
            }
            setTimeout(function() {
                r.disableFormElements(i)
            },
            13)
        }
        var i = e(this),
        s = i.data("remote") !== t,
        o = r.blankInputs(i, r.requiredInputSelector),
        u = r.nonBlankInputs(i, r.fileInputSelector);
        return r.allowAction(i, a) ? a() : r.stopEverything(n)
    }), e(document).delegate(r.formInputClickSelector, "click.rails", 
    function(t) {
        function i() {
            var e = n.attr("name"),
            t = e ? {
                name: e,
                value: n.val()
            }: null;
            n.closest("form").data("ujs:submit-button", t)
        }
        var n = e(this);
        return r.allowAction(n, i) ? i() : r.stopEverything(t)
    }), e(document).delegate(r.formSubmitSelector, "ajax:beforeSend.rails", 
    function(t) {
        this == t.target && r.disableFormElements(e(this))
    }), e(document).delegate(r.formSubmitSelector, "ajax:complete.rails", 
    function(t) {
        this == t.target && r.enableFormElements(e(this))
    }), e(function() {
        csrf_token = e("meta[name=csrf-token]").attr("content"),
        csrf_param = e("meta[name=csrf-param]").attr("content"),
        e('form input[name="' + csrf_param + '"]').val(csrf_token)
    }))
} (jQuery),
function(e) {
    var t = "hidden",
    n = "border-box",
    r = '<textarea tabindex="-1" style="position:absolute; top:-9999px; left:-9999px; right:auto; bottom:auto; -moz-box-sizing:content-box; -webkit-box-sizing:content-box; box-sizing:content-box; word-wrap:break-word; height:0 !important; min-height:0 !important; overflow:hidden">'
    ,
    i = ["fontFamily", "fontSize", "fontWeight", "fontStyle", "lineHeight", "letterSpacing", "textTransform", "wordSpacing", "textIndent"],
    s = "oninput",
    o = "onpropertychange",
    u = e(r)[0];
    u.setAttribute(s, "return"),
    e.isFunction(u[s]) || o in u ? e.fn.autosize = function(u) {
        return this.each(function() {
            function g() {
                var e,
                n;
                p || (p = !0, l.value = a.value, l.style.overflowY = a.style.overflowY, l.style.width = f.css("width"), l.scrollTop = 0, l.scrollTop = 9e4, e = l.scrollTop, n = t, e > h ? (e = h, n = "scroll") : e < c && (e = c), a.style.overflowY = n, a.style.height = e + m + "px", setTimeout(function() {
                    p = !1
                },
                1))
            }
            var a = this,
            f = e(a),
            l,
            c = f.height(),
            h = parseInt(f.css("maxHeight"), 10),
            p,
            d = i.length,
            v,
            m = 0;
            if (f.css("box-sizing") === n || f.css("-moz-box-sizing") === n || f.css("-webkit-box-sizing") === n) m = f.outerHeight() - f.height();
            if (f.data("mirror") || f.data("ismirror")) return;
            l = e(r).data("ismirror", !0).addClass(u || "autosizejs")[0],
            v = f.css("resize") === "none" ? "none": "horizontal",
            f.data("mirror", e(l)).css({
                overflow: t,
                overflowY: t,
                wordWrap: "break-word",
                resize: v
            }),
            h = h && h > 0 ? h: 9e4;
            while (d--) l.style[i[d]] = f.css(i[d]);
            e("body").append(l),
            o in a ? s in a ? a[s] = a.onkeyup = g: a[o] = g: a[s] = g,
            e(window).resize(g),
            f.bind("autosize", g),
            g()
        })
    }: e.fn.autosize = function() {
        return this
    }
} (jQuery),
//Color Animations
function(e, t) {
    function h(e, t, n) {
        var r = u[t.type] || {};
        return e == null ? n || !t.def ? null: t.def: (e = r.floor ? ~~e: parseFloat(e), isNaN(e) ? t.def: r.mod ? (e + r.mod) % r.mod: 0 > e ? 0: r.max < e ? r.max: e)
    }
    function p(t) {
        var n = s(),
        r = n._rgba = [];
        return t = t.toLowerCase(),
        c(i, 
        function(e, i) {
            var s,
            u = i.re.exec(t),
            a = u && i.parse(u),
            f = i.space || "rgba";
            if (a) return s = n[f](a),
            n[o[f].cache] = s[o[f].cache],
            r = n._rgba = s._rgba,
            !1
        }),
        r.length ? (r.join() === "0,0,0,0" && e.extend(r, l.transparent), n) : l[t]
    }
    function d(e, t, n) {
        return n = (n + 1) % 1,
        n * 6 < 1 ? e + (t - e) * n * 6: n * 2 < 1 ? t: n * 3 < 2 ? e + (t - e) * (2 / 3 - n) * 6: e
    }
    var n = "backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor",
    r = /^([\-+])=\s*(\d+\.?\d*)/,
    i = [{
        re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
        parse: function(e) {
            return [e[1], e[2], e[3], e[4]]
        }
    },
    {
        re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
        parse: function(e) {
            return [e[1] * 2.55, e[2] * 2.55, e[3] * 2.55, e[4]]
        }
    },
    {
        re: /#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})/,
        parse: function(e) {
            return [parseInt(e[1], 16), parseInt(e[2], 16), parseInt(e[3], 16)]
        }
    },
    {
        re: /#([a-f0-9])([a-f0-9])([a-f0-9])/,
        parse: function(e) {
            return [parseInt(e[1] + e[1], 16), parseInt(e[2] + e[2], 16), parseInt(e[3] + e[3], 16)]
        }
    },
    {
        re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
        space: "hsla",
        parse: function(e) {
            return [e[1], e[2] / 100, e[3] / 100, e[4]]
        }
    }],
    s = e.Color = function(t, n, r, i) {
        return new e.Color.fn.parse(t, n, r, i)
    },
    o = {
        rgba: {
            props: {
                red: {
                    idx: 0,
                    type: "byte"
                },
                green: {
                    idx: 1,
                    type: "byte"
                },
                blue: {
                    idx: 2,
                    type: "byte"
                }
            }
        },
        hsla: {
            props: {
                hue: {
                    idx: 0,
                    type: "degrees"
                },
                saturation: {
                    idx: 1,
                    type: "percent"
                },
                lightness: {
                    idx: 2,
                    type: "percent"
                }
            }
        }
    },
    u = {
        "byte": {
            floor: !0,
            max: 255
        },
        percent: {
            max: 1
        },
        degrees: {
            mod: 360,
            floor: !0
        }
    },
    a = s.support = {},
    f = e("<p>")[0],
    l,
    c = e.each;
    f.style.cssText = "background-color:rgba(1,1,1,.5)",
    a.rgba = f.style.backgroundColor.indexOf("rgba") > -1,
    c(o, 
    function(e, t) {
        t.cache = "_" + e,
        t.props.alpha = {
            idx: 3,
            type: "percent",
            def: 1
        }
    }),
    s.fn = e.extend(s.prototype, {
        parse: function(n, r, i, u) {
            if (n === t) return this._rgba = [null, null, null, null],
            this;
            if (n.jquery || n.nodeType) n = e(n).css(r),
            r = t;
            var a = this,
            f = e.type(n),
            d = this._rgba = [],
            v;
            r !== t && (n = [n, r, i, u], f = "array");
            if (f === "string") return this.parse(p(n) || l._default);
            if (f === "array") return c(o.rgba.props, 
            function(e, t) {
                d[t.idx] = h(n[t.idx], t)
            }),
            this;
            if (f === "object") return n instanceof s ? c(o, 
            function(e, t) {
                n[t.cache] && (a[t.cache] = n[t.cache].slice())
            }) : c(o, 
            function(t, r) {
                var i = r.cache;
                c(r.props, 
                function(e, t) {
                    if (!a[i] && r.to) {
                        if (e === "alpha" || n[e] == null) return;
                        a[i] = r.to(a._rgba)
                    }
                    a[i][t.idx] = h(n[e], t, !0)
                }),
                a[i] && e.inArray(null, a[i].slice(0, 3)) < 0 && (a[i][3] = 1, r.from && (a._rgba = r.from(a[i])))
            }),
            this
        },
        is: function(e) {
            var t = s(e),
            n = !0,
            r = this;
            return c(o, 
            function(e, i) {
                var s,
                o = t[i.cache];
                return o && (s = r[i.cache] || i.to && i.to(r._rgba) || [], c(i.props, 
                function(e, t) {
                    if (o[t.idx] != null) return n = o[t.idx] === s[t.idx],
                    n
                })),
                n
            }),
            n
        },
        _space: function() {
            var e = [],
            t = this;
            return c(o, 
            function(n, r) {
                t[r.cache] && e.push(n)
            }),
            e.pop()
        },
        transition: function(e, t) {
            var n = s(e),
            r = n._space(),
            i = o[r],
            a = this.alpha() === 0 ? s("transparent") : this,
            f = a[i.cache] || i.to(a._rgba),
            l = f.slice();
            return n = n[i.cache],
            c(i.props, 
            function(e, r) {
                var i = r.idx,
                s = f[i],
                o = n[i],
                a = u[r.type] || {};
                if (o === null) return;
                s === null ? l[i] = o: (a.mod && (o - s > a.mod / 2 ? s += a.mod: s - o > a.mod / 2 && (s -= a.mod)), l[i] = h((o - s) * t + s, r))
            }),
            this[r](l)
        },
        blend: function(t) {
            if (this._rgba[3] === 1) return this;
            var n = this._rgba.slice(),
            r = n.pop(),
            i = s(t)._rgba;
            return s(e.map(n, 
            function(e, t) {
                return (1 - r) * i[t] + r * e
            }))
        },
        toRgbaString: function() {
            var t = "rgba(",
            n = e.map(this._rgba, 
            function(e, t) {
                return e == null ? t > 2 ? 1: 0: e
            });
            return n[3] === 1 && (n.pop(), t = "rgb("),
            t + n.join() + ")"
        },
        toHslaString: function() {
            var t = "hsla(",
            n = e.map(this.hsla(), 
            function(e, t) {
                return e == null && (e = t > 2 ? 1: 0),
                t && t < 3 && (e = Math.round(e * 100) + "%"),
                e
            });
            return n[3] === 1 && (n.pop(), t = "hsl("),
            t + n.join() + ")"
        },
        toHexString: function(t) {
            var n = this._rgba.slice(),
            r = n.pop();
            return t && n.push(~~ (r * 255)),
            "#" + e.map(n, 
            function(e, t) {
                return e = (e || 0).toString(16),
                e.length === 1 ? "0" + e: e
            }).join("")
        },
        toString: function() {
            return this._rgba[3] === 0 ? "transparent": this.toRgbaString()
        }
    }),
    s.fn.parse.prototype = s.fn,
    o.hsla.to = function(e) {
        if (e[0] == null || e[1] == null || e[2] == null) return [null, null, null, e[3]];
        var t = e[0] / 255,
        n = e[1] / 255,
        r = e[2] / 255,
        i = e[3],
        s = Math.max(t, n, r),
        o = Math.min(t, n, r),
        u = s - o,
        a = s + o,
        f = a * .5,
        l,
        c;
        return o === s ? l = 0: t === s ? l = 60 * (n - r) / u + 360: n === s ? l = 60 * (r - t) / u + 120: l = 60 * (t - n) / u + 240,
        f === 0 || f === 1 ? c = f: f <= .5 ? c = u / a: c = u / (2 - a),
        [Math.round(l) % 360, c, f, i == null ? 1: i]
    },
    o.hsla.from = function(e) {
        if (e[0] == null || e[1] == null || e[2] == null) return [null, null, null, e[3]];
        var t = e[0] / 360,
        n = e[1],
        r = e[2],
        i = e[3],
        s = r <= .5 ? r * (1 + n) : r + n - r * n,
        o = 2 * r - s,
        u,
        a,
        f;
        return [Math.round(d(o, s, t + 1 / 3) * 255), Math.round(d(o, s, t) * 255), Math.round(d(o, s, t - 1 / 3) * 255), i]
    },
    c(o, 
    function(n, i) {
        var o = i.props,
        u = i.cache,
        a = i.to,
        f = i.from;
        s.fn[n] = function(n) {
            a && !this[u] && (this[u] = a(this._rgba));
            if (n === t) return this[u].slice();
            var r,
            i = e.type(n),
            l = i === "array" || i === "object" ? n: arguments,
            p = this[u].slice();
            return c(o, 
            function(e, t) {
                var n = l[i === "object" ? e: t.idx];
                n == null && (n = p[t.idx]),
                p[t.idx] = h(n, t)
            }),
            f ? (r = s(f(p)), r[u] = p, r) : s(p)
        },
        c(o, 
        function(t, i) {
            if (s.fn[t]) return;
            s.fn[t] = function(s) {
                var o = e.type(s),
                u = t === "alpha" ? this._hsla ? "hsla": "rgba": n,
                a = this[u](),
                f = a[i.idx],
                l;
                return o === "undefined" ? f: (o === "function" && (s = s.call(this, f), o = e.type(s)), s == null && i.empty ? this: (o === "string" && (l = r.exec(s), l && (s = f + parseFloat(l[2]) * (l[1] === "+" ? 1: -1))), a[i.idx] = s, this[u](a)))
            }
        })
    }),
    s.hook = function(t) {
        var n = t.split(" ");
        c(n, 
        function(t, n) {
            e.cssHooks[n] = {
                set: function(t, r) {
                    var i,
                    o,
                    u = "";
                    if (e.type(r) !== "string" || (i = p(r))) {
                        r = s(i || r);
                        if (!a.rgba && r._rgba[3] !== 1) {
                            o = n === "backgroundColor" ? t.parentNode: t;
                            while ((u === "" || u === "transparent") && o && o.style) try {
                                u = e.css(o, "backgroundColor"),
                                o = o.parentNode
                            } catch(f) {}
                            r = r.blend(u && u !== "transparent" ? u: "_default")
                        }
                        r = r.toRgbaString()
                    }
                    try {
                        t.style[n] = r
                    } catch(r) {}
                }
            },
            e.fx.step[n] = function(t) {
                t.colorInit || (t.start = s(t.elem, n), t.end = s(t.end), t.colorInit = !0),
                e.cssHooks[n].set(t.elem, t.start.transition(t.end, t.pos))
            }
        })
    },
    s.hook(n),
    e.cssHooks.borderColor = {
        expand: function(e) {
            var t = {};
            return c(["Top", "Right", "Bottom", "Left"], 
            function(n, r) {
                t["border" + r + "Color"] = e
            }),
            t
        }
    },
    l = e.Color.names = {
        aqua: "#00ffff",
        black: "#000000",
        blue: "#0000ff",
        fuchsia: "#ff00ff",
        gray: "#808080",
        green: "#008000",
        lime: "#00ff00",
        maroon: "#800000",
        navy: "#000080",
        olive: "#808000",
        purple: "#800080",
        red: "#ff0000",
        silver: "#c0c0c0",
        teal: "#008080",
        white: "#ffffff",
        yellow: "#ffff00",
        transparent: [null, null, null, 0],
        _default: "#ffffff"
    }
} (jQuery);
// wysihtml5区域
var wysihtml5ParserRules = {
    classes: {
        "wysiwyg-clear-both": 1,
        "wysiwyg-clear-left": 1,
        "wysiwyg-clear-right": 1,
        "wysiwyg-color-aqua": 1,
        "wysiwyg-color-black": 1,
        "wysiwyg-color-blue": 1,
        "wysiwyg-color-fuchsia": 1,
        "wysiwyg-color-gray": 1,
        "wysiwyg-color-green": 1,
        "wysiwyg-color-lime": 1,
        "wysiwyg-color-maroon": 1,
        "wysiwyg-color-navy": 1,
        "wysiwyg-color-olive": 1,
        "wysiwyg-color-purple": 1,
        "wysiwyg-color-red": 1,
        "wysiwyg-color-silver": 1,
        "wysiwyg-color-teal": 1,
        "wysiwyg-color-white": 1,
        "wysiwyg-color-yellow": 1,
        "wysiwyg-float-left": 1,
        "wysiwyg-float-right": 1,
        "wysiwyg-font-size-large": 1,
        "wysiwyg-font-size-larger": 1,
        "wysiwyg-font-size-medium": 1,
        "wysiwyg-font-size-small": 1,
        "wysiwyg-font-size-smaller": 1,
        "wysiwyg-font-size-x-large": 1,
        "wysiwyg-font-size-x-small": 1,
        "wysiwyg-font-size-xx-large": 1,
        "wysiwyg-font-size-xx-small": 1,
        "wysiwyg-text-align-center": 1,
        "wysiwyg-text-align-justify": 1,
        "wysiwyg-text-align-left": 1,
        "wysiwyg-text-align-right": 1
    },
    tags: {
        tr: {
            add_class: {
                align: "align_text"
            }
        },
        strike: {
            remove: 1
        },
        form: {
            rename_tag: "div"
        },
        rt: {
            rename_tag: "span"
        },
        code: {},
        acronym: {
            rename_tag: "span"
        },
        br: {
            add_class: {
                clear: "clear_br"
            }
        },
        details: {
            rename_tag: "div"
        },
        h4: {
            add_class: {
                align: "align_text"
            }
        },
        em: {},
        title: {
            remove: 1
        },
        multicol: {
            rename_tag: "div"
        },
        figure: {
            rename_tag: "div"
        },
        xmp: {
            rename_tag: "span"
        },
        small: {
            rename_tag: "span",
            set_class: "wysiwyg-font-size-smaller"
        },
        area: {
            remove: 1
        },
        time: {
            rename_tag: "span"
        },
        dir: {
            rename_tag: "ul"
        },
        bdi: {
            rename_tag: "span"
        },
        command: {
            remove: 1
        },
        ul: {},
        progress: {
            rename_tag: "span"
        },
        dfn: {
            rename_tag: "span"
        },
        iframe: {
            remove: 1
        },
        figcaption: {
            rename_tag: "div"
        },
        a: {
            check_attributes: {
                href: "href"
            },
            set_attributes: {
                rel: "nofollow",
                target: "_blank"
            }
        },
        img: {
            check_attributes: {
                width: "numbers",
                alt: "alt",
                src: "src",
                height: "numbers"
            },
            add_class: {
                align: "align_img"
            }
        },
        rb: {
            rename_tag: "span"
        },
        footer: {
            rename_tag: "div"
        },
        noframes: {
            remove: 1
        },
        abbr: {
            rename_tag: "span"
        },
        u: {},
        bgsound: {
            remove: 1
        },
        sup: {
            rename_tag: "span"
        },
        address: {
            rename_tag: "div"
        },
        basefont: {
            remove: 1
        },
        nav: {
            rename_tag: "div"
        },
        h1: {
            add_class: {
                align: "align_text"
            }
        },
        head: {
            remove: 1
        },
        tbody: {
            add_class: {
                align: "align_text"
            }
        },
        dd: {
            rename_tag: "div"
        },
        s: {
            rename_tag: "span"
        },
        li: {},
        td: {
            check_attributes: {
                rowspan: "numbers",
                colspan: "numbers"
            },
            add_class: {
                align: "align_text"
            }
        },
        object: {
            remove: 1
        },
        div: {
            add_class: {
                align: "align_text"
            }
        },
        option: {
            rename_tag: "span"
        },
        select: {
            rename_tag: "span"
        },
        i: {},
        track: {
            remove: 1
        },
        wbr: {
            remove: 1
        },
        fieldset: {
            rename_tag: "div"
        },
        big: {
            rename_tag: "span",
            set_class: "wysiwyg-font-size-larger"
        },
        button: {
            rename_tag: "span"
        },
        noscript: {
            remove: 1
        },
        svg: {
            remove: 1
        },
        input: {
            remove: 1
        },
        table: {},
        keygen: {
            remove: 1
        },
        h5: {
            add_class: {
                align: "align_text"
            }
        },
        meta: {
            remove: 1
        },
        map: {
            rename_tag: "div"
        },
        isindex: {
            remove: 1
        },
        mark: {
            rename_tag: "span"
        },
        caption: {
            add_class: {
                align: "align_text"
            }
        },
        tfoot: {
            add_class: {
                align: "align_text"
            }
        },
        base: {
            remove: 1
        },
        video: {
            remove: 1
        },
        strong: {},
        canvas: {
            remove: 1
        },
        output: {
            rename_tag: "span"
        },
        marquee: {
            rename_tag: "span"
        },
        b: {},
        q: {
            check_attributes: {
                cite: "url"
            }
        },
        applet: {
            remove: 1
        },
        span: {},
        rp: {
            rename_tag: "span"
        },
        spacer: {
            remove: 1
        },
        source: {
            remove: 1
        },
        aside: {
            rename_tag: "div"
        },
        frame: {
            remove: 1
        },
        section: {
            rename_tag: "div"
        },
        body: {
            rename_tag: "div"
        },
        ol: {},
        nobr: {
            rename_tag: "span"
        },
        html: {
            rename_tag: "div"
        },
        summary: {
            rename_tag: "span"
        },
        "var": {
            rename_tag: "span"
        },
        del: {
            remove: 1
        },
        blockquote: {
            check_attributes: {
                cite: "url"
            }
        },
        style: {
            remove: 1
        },
        device: {
            remove: 1
        },
        meter: {
            rename_tag: "span"
        },
        h3: {
            add_class: {
                align: "align_text"
            }
        },
        textarea: {
            rename_tag: "span"
        },
        embed: {
            remove: 1
        },
        hgroup: {
            rename_tag: "div"
        },
        font: {
            rename_tag: "span",
            add_class: {
                size: "size_font"
            }
        },
        tt: {
            rename_tag: "span"
        },
        noembed: {
            remove: 1
        },
        thead: {
            add_class: {
                align: "align_text"
            }
        },
        blink: {
            rename_tag: "span"
        },
        plaintext: {
            rename_tag: "span"
        },
        xml: {
            remove: 1
        },
        h6: {
            add_class: {
                align: "align_text"
            }
        },
        param: {
            remove: 1
        },
        th: {
            check_attributes: {
                rowspan: "numbers",
                colspan: "numbers"
            },
            add_class: {
                align: "align_text"
            }
        },
        legend: {
            rename_tag: "span"
        },
        hr: {},
        label: {
            rename_tag: "span"
        },
        dl: {
            rename_tag: "div"
        },
        kbd: {
            rename_tag: "span"
        },
        listing: {
            rename_tag: "div"
        },
        dt: {
            rename_tag: "span"
        },
        nextid: {
            remove: 1
        },
        pre: {},
        center: {
            rename_tag: "div",
            set_class: "wysiwyg-text-align-center"
        },
        audio: {
            remove: 1
        },
        datalist: {
            rename_tag: "span"
        },
        samp: {
            rename_tag: "span"
        },
        col: {
            remove: 1
        },
        article: {
            rename_tag: "div"
        },
        cite: {},
        link: {
            remove: 1
        },
        script: {
            remove: 1
        },
        bdo: {
            rename_tag: "span"
        },
        menu: {
            rename_tag: "ul"
        },
        colgroup: {
            remove: 1
        },
        ruby: {
            rename_tag: "span"
        },
        h2: {
            add_class: {
                align: "align_text"
            }
        },
        ins: {
            rename_tag: "span"
        },
        p: {
            add_class: {
                align: "align_text"
            }
        },
        sub: {
            rename_tag: "span"
        },
        comment: {
            remove: 1
        },
        frameset: {
            remove: 1
        },
        optgroup: {
            rename_tag: "span"
        },
        header: {
            rename_tag: "div"
        }
    }
},
wysihtml5 = {
    version: "0.3.0",
    commands: {},
    dom: {},
    quirks: {},
    toolbar: {},
    lang: {},
    selection: {},
    views: {},
    INVISIBLE_SPACE: "﻿",
    EMPTY_FUNCTION: function() {},
    ELEMENT_NODE: 1,
    TEXT_NODE: 3,
    BACKSPACE_KEY: 8,
    ENTER_KEY: 13,
    ESCAPE_KEY: 27,
    SPACE_KEY: 32,
    DELETE_KEY: 46
};
window.rangy = function() {
    function u(n, r) {
        var i = typeof n[r];
        return i == t || i == e && !!n[r] || i == "unknown"
    }
    function a(t, n) {
        return typeof t[n] == e && !!t[n]
    }
    function f(e, t) {
        return typeof e[t] != n
    }
    function l(e) {
        return function(t, n) {
            var r = n.length;
            while (r--) if (!e(t, n[r])) return ! 1;
            return ! 0
        }
    }
    function d(e) {
        return e && c(e, o) && p(e, s)
    }
    function m(e) {
        window.alert("Rangy not supported in your browser. Reason: " + e),
        v.initialized = !0,
        v.supported = !1
    }
    function g(e) {
        var t = "Rangy warning: " + e;
        v.config.alertOnWarn ? window.alert(t) : typeof window.console != n && typeof window.console.log != n && window.console.log(t)
    }
    function w() {
        if (v.initialized) return;
        var e,
        t = !1,
        n = !1;
        u(document, "createRange") && (e = document.createRange(), c(e, i) && p(e, r) && (t = !0), e.detach());
        var s = a(document, "body") ? document.body: document.getElementsByTagName("body")[0];
        s && u(s, "createTextRange") && (e = s.createTextRange(), d(e) && (n = !0)),
        !t && !n && m("Neither Range nor TextRange are implemented"),
        v.initialized = !0,
        v.features = {
            implementsDomRange: t,
            implementsTextRange: n
        };
        var o = b.concat(y);
        for (var f = 0, l = o.length; f < l; ++f) try {
            o[f](v)
        } catch(h) {
            a(window, "console") && u(window.console, "log") && window.console.log("Init listener threw an exception. Continuing.", h)
        }
    }
    function S(e) {
        e = e || window,
        w();
        for (var t = 0, n = E.length; t < n; ++t) E[t](e)
    }
    function x(e) {
        this.name = e,
        this.initialized = !1,
        this.supported = !1
    }
    var e = "object",
    t = "function",
    n = "undefined",
    r = ["startContainer", "startOffset", "endContainer", "endOffset", "collapsed", "commonAncestorContainer", "START_TO_START", "START_TO_END", "END_TO_START", "END_TO_END"],
    i = ["setStart", "setStartBefore", "setStartAfter", "setEnd", "setEndBefore", "setEndAfter", "collapse", "selectNode", "selectNodeContents", "compareBoundaryPoints", "deleteContents", "extractContents", "cloneContents", "insertNode", "surroundContents", "cloneRange", "toString", "detach"],
    s = ["boundingHeight", "boundingLeft", "boundingTop", "boundingWidth", "htmlText", "text"],
    o = ["collapse", "compareEndPoints", "duplicate", "getBookmark", "moveToBookmark", "moveToElementText", "parentElement", "pasteHTML", "select", "setEndPoint", "getBoundingClientRect"],
    c = l(u),
    h = l(a),
    p = l(f),
    v = {
        version: "1.2.2",
        initialized: !1,
        supported: !0,
        util: {
            isHostMethod: u,
            isHostObject: a,
            isHostProperty: f,
            areHostMethods: c,
            areHostObjects: h,
            areHostProperties: p,
            isTextRange: d
        },
        features: {},
        modules: {},
        config: {
            alertOnWarn: !1,
            preferTextRange: !1
        }
    };
    v.fail = m,
    v.warn = g,
    {}.hasOwnProperty ? v.util.extend = function(e, t) {
        for (var n in t) t.hasOwnProperty(n) && (e[n] = t[n]);
        return e
    }: m("hasOwnProperty not supported");
    var y = [],
    b = [];
    v.init = w,
    v.addInitListener = function(e) {
        v.initialized ? e(v) : y.push(e)
    };
    var E = [];
    v.addCreateMissingNativeApiListener = function(e) {
        E.push(e)
    },
    v.createMissingNativeApi = S,
    x.prototype.fail = function(e) {
        throw this.initialized = !0,
        this.supported = !1,
        new Error("Module '" + this.name + "' failed to load: " + e)
    },
    x.prototype.warn = function(e) {
        v.warn("Module " + this.name + ": " + e)
    },
    x.prototype.createError = function(e) {
        return new Error("Error in Rangy " + this.name + " module: " + e)
    },
    v.createModule = function(e, t) {
        var n = new x(e);
        v.modules[e] = n,
        b.push(function(e) {
            t(e, n),
            n.initialized = !0,
            n.supported = !0
        })
    },
    v.requireModules = function(e) {
        for (var t = 0, n = e.length, r, i; t < n; ++t) {
            i = e[t],
            r = v.modules[i];
            if (!r || !(r instanceof x)) throw new Error("Module '" + i + "' not found");
            if (!r.supported) throw new Error("Module '" + i + "' not supported")
        }
    };
    var T = !1,
    N = function(e) {
        T || (T = !0, v.initialized || w())
    };
    if (typeof window == n) {
        m("No window found");
        return
    }
    if (typeof document == n) {
        m("No document found");
        return
    }
    return u(document, "addEventListener") && document.addEventListener("DOMContentLoaded", N, !1),
    u(window, "addEventListener") ? window.addEventListener("load", N, !1) : u(window, "attachEvent") ? window.attachEvent("onload", N) : m("Window does not have required addEventListener or attachEvent method"),
    v
} (),
rangy.createModule("DomUtil", 
function(e, t) {
    function u(e) {
        var t;
        return typeof e.namespaceURI == n || (t = e.namespaceURI) === null || t == "http://www.w3.org/1999/xhtml"
    }
    function a(e) {
        var t = e.parentNode;
        return t.nodeType == 1 ? t: null
    }
    function f(e) {
        var t = 0;
        while (e = e.previousSibling) t++;
        return t
    }
    function l(e) {
        var t;
        return d(e) ? e.length: (t = e.childNodes) ? t.length: 0
    }
    function c(e, t) {
        var n = [],
        r;
        for (r = e; r; r = r.parentNode) n.push(r);
        for (r = t; r; r = r.parentNode) if (o(n, r)) return r;
        return null
    }
    function h(e, t, n) {
        var r = n ? t: t.parentNode;
        while (r) {
            if (r === e) return ! 0;
            r = r.parentNode
        }
        return ! 1
    }
    function p(e, t, n) {
        var r,
        i = n ? e: e.parentNode;
        while (i) {
            r = i.parentNode;
            if (r === t) return i;
            i = r
        }
        return null
    }
    function d(e) {
        var t = e.nodeType;
        return t == 3 || t == 4 || t == 8
    }
    function v(e, t) {
        var n = t.nextSibling,
        r = t.parentNode;
        return n ? r.insertBefore(e, n) : r.appendChild(e),
        e
    }
    function m(e, t) {
        var n = e.cloneNode(!1);
        return n.deleteData(0, t),
        e.deleteData(t, e.length - t),
        v(n, e),
        n
    }
    function g(e) {
        if (e.nodeType == 9) return e;
        if (typeof e.ownerDocument != n) return e.ownerDocument;
        if (typeof e.document != n) return e.document;
        if (e.parentNode) return g(e.parentNode);
        throw new Error("getDocument: no document found for node")
    }
    function y(e) {
        var t = g(e);
        if (typeof t.defaultView != n) return t.defaultView;
        if (typeof t.parentWindow != n) return t.parentWindow;
        throw new Error("Cannot get a window object for node")
    }
    function b(e) {
        if (typeof e.contentDocument != n) return e.contentDocument;
        if (typeof e.contentWindow != n) return e.contentWindow.document;
        throw new Error("getIframeWindow: No Document object found for iframe element")
    }
    function w(e) {
        if (typeof e.contentWindow != n) return e.contentWindow;
        if (typeof e.contentDocument != n) return e.contentDocument.defaultView;
        throw new Error("getIframeWindow: No Window object found for iframe element")
    }
    function E(e) {
        return r.isHostObject(e, "body") ? e.body: e.getElementsByTagName("body")[0]
    }
    function S(e) {
        var t;
        while (t = e.parentNode) e = t;
        return e
    }
    function x(e, t, n, r) {
        var i,
        s,
        o,
        u,
        a;
        if (e == n) return t === r ? 0: t < r ? -1: 1;
        if (i = p(n, e, !0)) return t <= f(i) ? -1: 1;
        if (i = p(e, n, !0)) return f(i) < r ? -1: 1;
        s = c(e, n),
        o = e === s ? s: p(e, s, !0),
        u = n === s ? s: p(n, s, !0);
        if (o === u) throw new Error("comparePoints got to case 4 and childA and childB are the same!");
        a = s.firstChild;
        while (a) {
            if (a === o) return - 1;
            if (a === u) return 1;
            a = a.nextSibling
        }
        throw new Error("Should not be here!")
    }
    function T(e) {
        var t = g(e).createDocumentFragment(),
        n;
        while (n = e.firstChild) t.appendChild(n);
        return t
    }
    function N(e) {
        if (!e) return "[No node]";
        if (d(e)) return '"' + e.data + '"';
        if (e.nodeType == 1) {
            var t = e.id ? ' id="' + e.id + '"': "";
            return "<" + e.nodeName + t + ">[" + e.childNodes.length + "]"
        }
        return e.nodeName
    }
    function C(e) {
        this.root = e,
        this._next = e
    }
    function k(e) {
        return new C(e)
    }
    function L(e, t) {
        this.node = e,
        this.offset = t
    }
    function A(e) {
        this.code = this[e],
        this.codeName = e,
        this.message = "DOMException: " + this.codeName
    }
    var n = "undefined",
    r = e.util;
    r.areHostMethods(document, ["createDocumentFragment", "createElement", "createTextNode"]) || t.fail("document missing a Node creation method"),
    r.isHostMethod(document, "getElementsByTagName") || t.fail("document missing getElementsByTagName method");
    var i = document.createElement("div");
    r.areHostMethods(i, ["insertBefore", "appendChild", "cloneNode"] || !r.areHostObjects(i, ["previousSibling", "nextSibling", "childNodes", "parentNode"])) || t.fail("Incomplete Element implementation"),
    r.isHostProperty(i, "innerHTML") || t.fail("Element is missing innerHTML property");
    var s = document.createTextNode("test");
    r.areHostMethods(s, ["splitText", "deleteData", "insertData", "appendData", "cloneNode"] || !r.areHostObjects(i, ["previousSibling", "nextSibling", "childNodes", "parentNode"]) || !r.areHostProperties(s, ["data"])) || t.fail("Incomplete Text Node implementation");
    var o = function(e, t) {
        var n = e.length;
        while (n--) if (e[n] === t) return ! 0;
        return ! 1
    };
    C.prototype = {
        _current: null,
        hasNext: function() {
            return !! this._next
        },
        next: function() {
            var e = this._current = this._next,
            t,
            n;
            if (this._current) {
                t = e.firstChild;
                if (t) this._next = t;
                else {
                    n = null;
                    while (e !== this.root && !(n = e.nextSibling)) e = e.parentNode;
                    this._next = n
                }
            }
            return this._current
        },
        detach: function() {
            this._current = this._next = this.root = null
        }
    },
    L.prototype = {
        equals: function(e) {
            return this.node === e.node & this.offset == e.offset
        },
        inspect: function() {
            return "[DomPosition(" + N(this.node) + ":" + this.offset + ")]"
        }
    },
    A.prototype = {
        INDEX_SIZE_ERR: 1,
        HIERARCHY_REQUEST_ERR: 3,
        WRONG_DOCUMENT_ERR: 4,
        NO_MODIFICATION_ALLOWED_ERR: 7,
        NOT_FOUND_ERR: 8,
        NOT_SUPPORTED_ERR: 9,
        INVALID_STATE_ERR: 11
    },
    A.prototype.toString = function() {
        return this.message
    },
    e.dom = {
        arrayContains: o,
        isHtmlNamespace: u,
        parentElement: a,
        getNodeIndex: f,
        getNodeLength: l,
        getCommonAncestor: c,
        isAncestorOf: h,
        getClosestAncestorIn: p,
        isCharacterDataNode: d,
        insertAfter: v,
        splitDataNode: m,
        getDocument: g,
        getWindow: y,
        getIframeWindow: w,
        getIframeDocument: b,
        getBody: E,
        getRootContainer: S,
        comparePoints: x,
        inspectNode: N,
        fragmentFromNodeChildren: T,
        createIterator: k,
        DomPosition: L
    },
    e.DOMException = A
}),
rangy.createModule("DomRange", 
function(e, t) {
    function s(e, t) {
        return e.nodeType != 3 && (n.isAncestorOf(e, t.startContainer, !0) || n.isAncestorOf(e, t.endContainer, !0))
    }
    function o(e) {
        return n.getDocument(e.startContainer)
    }
    function u(e, t, n) {
        var r = e._listeners[t];
        if (r) for (var i = 0, s = r.length; i < s; ++i) r[i].call(e, {
            target: e,
            args: n
        })
    }
    function a(e) {
        return new r(e.parentNode, n.getNodeIndex(e))
    }
    function f(e) {
        return new r(e.parentNode, n.getNodeIndex(e) + 1)
    }
    function l(e, t, r) {
        var i = e.nodeType == 11 ? e.firstChild: e;
        return n.isCharacterDataNode(t) ? r == t.length ? n.insertAfter(e, t) : t.parentNode.insertBefore(e, r == 0 ? t: n.splitDataNode(t, r)) : r >= t.childNodes.length ? t.appendChild(e) : t.insertBefore(e, t.childNodes[r]),
        i
    }
    function c(e) {
        var t;
        for (var n, r = o(e.range).createDocumentFragment(), s; n = e.next();) {
            t = e.isPartiallySelectedSubtree(),
            n = n.cloneNode(!t),
            t && (s = e.getSubtreeIterator(), n.appendChild(c(s)), s.detach(!0));
            if (n.nodeType == 10) throw new i("HIERARCHY_REQUEST_ERR");
            r.appendChild(n)
        }
        return r
    }
    function h(e, t, r) {
        var i,
        s;
        r = r || {
            stop: !1
        };
        for (var o, u; o = e.next();) if (e.isPartiallySelectedSubtree()) {
            if (t(o) === !1) {
                r.stop = !0;
                return
            }
            u = e.getSubtreeIterator(),
            h(u, t, r),
            u.detach(!0);
            if (r.stop) return
        } else {
            i = n.createIterator(o);
            while (s = i.next()) if (t(s) === !1) {
                r.stop = !0;
                return
            }
        }
    }
    function p(e) {
        var t;
        while (e.next()) e.isPartiallySelectedSubtree() ? (t = e.getSubtreeIterator(), p(t), t.detach(!0)) : e.remove()
    }
    function d(e) {
        for (var t, n = o(e.range).createDocumentFragment(), r; t = e.next();) {
            e.isPartiallySelectedSubtree() ? (t = t.cloneNode(!1), r = e.getSubtreeIterator(), t.appendChild(d(r)), r.detach(!0)) : e.remove();
            if (t.nodeType == 10) throw new i("HIERARCHY_REQUEST_ERR");
            n.appendChild(t)
        }
        return n
    }
    function v(e, t, n) {
        var r = !!t && !!t.length,
        i,
        s = !!n;
        r && (i = new RegExp("^(" + t.join("|") + ")$"));
        var o = [];
        return h(new g(e, !1), 
        function(e) { (!r || i.test(e.nodeType)) && (!s || n(e)) && o.push(e)
        }),
        o
    }
    function m(e) {
        var t = typeof e.getName == "undefined" ? "Range": e.getName();
        return "[" + t + "(" + n.inspectNode(e.startContainer) + ":" + e.startOffset + ", " + n.inspectNode(e.endContainer) + ":" + e.endOffset + ")]"
    }
    function g(e, t) {
        this.range = e,
        this.clonePartiallySelectedTextNodes = t;
        if (!e.collapsed) {
            this.sc = e.startContainer,
            this.so = e.startOffset,
            this.ec = e.endContainer,
            this.eo = e.endOffset;
            var r = e.commonAncestorContainer;
            this.sc === this.ec && n.isCharacterDataNode(this.sc) ? (this.isSingleCharacterDataNode = !0, this._first = this._last = this._next = this.sc) : (this._first = this._next = this.sc === r && !n.isCharacterDataNode(this.sc) ? this.sc.childNodes[this.so] : n.getClosestAncestorIn(this.sc, r, !0), this._last = this.ec === r && !n.isCharacterDataNode(this.ec) ? this.ec.childNodes[this.eo - 1] : n.getClosestAncestorIn(this.ec, r, !0))
        }
    }
    function y(e) {
        this.code = this[e],
        this.codeName = e,
        this.message = "RangeException: " + this.codeName
    }
    function b(e, t, n) {
        this.nodes = v(e, t, n),
        this._next = this.nodes[0],
        this._position = 0
    }
    function N(e) {
        return function(t, r) {
            var i,
            s = r ? t: t.parentNode;
            while (s) {
                i = s.nodeType;
                if (n.arrayContains(e, i)) return s;
                s = s.parentNode
            }
            return null
        }
    }
    function O(e, t) {
        if (A(e, t)) throw new y("INVALID_NODE_TYPE_ERR")
    }
    function M(e) {
        if (!e.startContainer) throw new i("INVALID_STATE_ERR")
    }
    function _(e, t) {
        if (!n.arrayContains(t, e.nodeType)) throw new y("INVALID_NODE_TYPE_ERR")
    }
    function D(e, t) {
        if (t < 0 || t > (n.isCharacterDataNode(e) ? e.length: e.childNodes.length)) throw new i("INDEX_SIZE_ERR")
    }
    function P(e, t) {
        if (k(e, !0) !== k(t, !0)) throw new i("WRONG_DOCUMENT_ERR")
    }
    function H(e) {
        if (L(e, !0)) throw new i("NO_MODIFICATION_ALLOWED_ERR")
    }
    function B(e, t) {
        if (!e) throw new i(t)
    }
    function j(e) {
        return ! n.arrayContains(E, e.nodeType) && !k(e, !0)
    }
    function F(e, t) {
        return t <= (n.isCharacterDataNode(e) ? e.length: e.childNodes.length)
    }
    function I(e) {
        M(e);
        if (j(e.startContainer) || j(e.endContainer) || !F(e.startContainer, e.startOffset) || !F(e.endContainer, e.endOffset)) throw new Error("Range error: Range is no longer valid after DOM mutation (" + e.inspect() + ")")
    }
    function Z() {}
    function et(e) {
        e.START_TO_START = X,
        e.START_TO_END = V,
        e.END_TO_END = $,
        e.END_TO_START = J,
        e.NODE_BEFORE = K,
        e.NODE_AFTER = Q,
        e.NODE_BEFORE_AND_AFTER = G,
        e.NODE_INSIDE = Y
    }
    function tt(e) {
        et(e),
        et(e.prototype)
    }
    function nt(e, t) {
        return function() {
            I(this);
            var r = this.startContainer,
            i = this.startOffset,
            s = this.commonAncestorContainer,
            o = new g(this, !0),
            u,
            a;
            r !== s && (u = n.getClosestAncestorIn(r, s, !0), a = f(u), r = a.node, i = a.offset),
            h(o, H),
            o.reset();
            var l = e(o);
            return o.detach(),
            t(this, r, i, r, i),
            l
        }
    }
    function rt(t, r, i) {
        function o(e, t) {
            return function(n) {
                M(this),
                _(n, w),
                _(C(n), E);
                var r = (e ? a: f)(n); (t ? u: l)(this, r.node, r.offset)
            }
        }
        function u(e, t, i) {
            var s = e.endContainer,
            o = e.endOffset;
            if (t !== e.startContainer || i !== e.startOffset) {
                if (C(t) != C(s) || n.comparePoints(t, i, s, o) == 1) s = t,
                o = i;
                r(e, t, i, s, o)
            }
        }
        function l(e, t, i) {
            var s = e.startContainer,
            o = e.startOffset;
            if (t !== e.endContainer || i !== e.endOffset) {
                if (C(t) != C(s) || n.comparePoints(t, i, s, o) == -1) s = t,
                o = i;
                r(e, s, o, t, i)
            }
        }
        function c(e, t, n) { (t !== e.startContainer || n !== e.startOffset || t !== e.endContainer || n !== e.endOffset) && r(e, t, n, t, n)
        }
        t.prototype = new Z,
        e.util.extend(t.prototype, {
            setStart: function(e, t) {
                M(this),
                O(e, !0),
                D(e, t),
                u(this, e, t)
            },
            setEnd: function(e, t) {
                M(this),
                O(e, !0),
                D(e, t),
                l(this, e, t)
            },
            setStartBefore: o(!0, !0),
            setStartAfter: o(!1, !0),
            setEndBefore: o(!0, !1),
            setEndAfter: o(!1, !1),
            collapse: function(e) {
                I(this),
                e ? r(this, this.startContainer, this.startOffset, this.startContainer, this.startOffset) : r(this, this.endContainer, this.endOffset, this.endContainer, this.endOffset)
            },
            selectNodeContents: function(e) {
                M(this),
                O(e, !0),
                r(this, e, 0, e, n.getNodeLength(e))
            },
            selectNode: function(e) {
                M(this),
                O(e, !1),
                _(e, w);
                var t = a(e),
                n = f(e);
                r(this, t.node, t.offset, n.node, n.offset)
            },
            extractContents: nt(d, r),
            deleteContents: nt(p, r),
            canSurroundContents: function() {
                I(this),
                H(this.startContainer),
                H(this.endContainer);
                var e = new g(this, !0),
                t = e._first && s(e._first, this) || e._last && s(e._last, this);
                return e.detach(),
                !t
            },
            detach: function() {
                i(this)
            },
            splitBoundaries: function() {
                I(this);
                var e = this.startContainer,
                t = this.startOffset,
                i = this.endContainer,
                s = this.endOffset,
                o = e === i;
                n.isCharacterDataNode(i) && s > 0 && s < i.length && n.splitDataNode(i, s),
                n.isCharacterDataNode(e) && t > 0 && t < e.length && (e = n.splitDataNode(e, t), o ? (s -= t, i = e) : i == e.parentNode && s >= n.getNodeIndex(e) && s++, t = 0),
                r(this, e, t, i, s)
            },
            normalizeBoundaries: function() {
                I(this);
                var e = this.startContainer,
                t = this.startOffset,
                i = this.endContainer,
                s = this.endOffset,
                o = function(e) {
                    var t = e.nextSibling;
                    t && t.nodeType == e.nodeType && (i = e, s = e.length, e.appendData(t.data), t.parentNode.removeChild(t))
                },
                u = function(r) {
                    var o = r.previousSibling;
                    if (o && o.nodeType == r.nodeType) {
                        e = r;
                        var u = r.length;
                        t = o.length,
                        r.insertData(0, o.data),
                        o.parentNode.removeChild(o);
                        if (e == i) s += t,
                        i = e;
                        else if (i == r.parentNode) {
                            var a = n.getNodeIndex(r);
                            s == a ? (i = r, s = u) : s > a && s--
                        }
                    }
                },
                a = !0;
                if (n.isCharacterDataNode(i)) i.length == s && o(i);
                else {
                    if (s > 0) {
                        var f = i.childNodes[s - 1];
                        f && n.isCharacterDataNode(f) && o(f)
                    }
                    a = !this.collapsed
                }
                if (a) {
                    if (n.isCharacterDataNode(e)) t == 0 && u(e);
                    else if (t < e.childNodes.length) {
                        var l = e.childNodes[t];
                        l && n.isCharacterDataNode(l) && u(l)
                    }
                } else e = i,
                t = s;
                r(this, e, t, i, s)
            },
            collapseToPoint: function(e, t) {
                M(this),
                O(e, !0),
                D(e, t),
                c(this, e, t)
            }
        }),
        tt(t)
    }
    function it(e) {
        e.collapsed = e.startContainer === e.endContainer && e.startOffset === e.endOffset,
        e.commonAncestorContainer = e.collapsed ? e.startContainer: n.getCommonAncestor(e.startContainer, e.endContainer)
    }
    function st(e, t, n, r, i) {
        var s = e.startContainer !== t || e.startOffset !== n,
        o = e.endContainer !== r || e.endOffset !== i;
        e.startContainer = t,
        e.startOffset = n,
        e.endContainer = r,
        e.endOffset = i,
        it(e),
        u(e, "boundarychange", {
            startMoved: s,
            endMoved: o
        })
    }
    function ot(e) {
        M(e),
        e.startContainer = e.startOffset = e.endContainer = e.endOffset = null,
        e.collapsed = e.commonAncestorContainer = null,
        u(e, "detach", null),
        e._listeners = null
    }
    function ut(e) {
        this.startContainer = e,
        this.startOffset = 0,
        this.endContainer = e,
        this.endOffset = 0,
        this._listeners = {
            boundarychange: [],
            detach: []
        },
        it(this)
    }
    e.requireModules(["DomUtil"]);
    var n = e.dom,
    r = n.DomPosition,
    i = e.DOMException;
    g.prototype = {
        _current: null,
        _next: null,
        _first: null,
        _last: null,
        isSingleCharacterDataNode: !1,
        reset: function() {
            this._current = null,
            this._next = this._first
        },
        hasNext: function() {
            return !! this._next
        },
        next: function() {
            var e = this._current = this._next;
            return e && (this._next = e !== this._last ? e.nextSibling: null, n.isCharacterDataNode(e) && this.clonePartiallySelectedTextNodes && (e === this.ec && (e = e.cloneNode(!0)).deleteData(this.eo, e.length - this.eo), this._current === this.sc && (e = e.cloneNode(!0)).deleteData(0, this.so))),
            e
        },
        remove: function() {
            var e = this._current,
            t,
            r; ! n.isCharacterDataNode(e) || e !== this.sc && e !== this.ec ? e.parentNode && e.parentNode.removeChild(e) : (t = e === this.sc ? this.so: 0, r = e === this.ec ? this.eo: e.length, t != r && e.deleteData(t, r - t))
        },
        isPartiallySelectedSubtree: function() {
            var e = this._current;
            return s(e, this.range)
        },
        getSubtreeIterator: function() {
            var e;
            if (this.isSingleCharacterDataNode) e = this.range.cloneRange(),
            e.collapse();
            else {
                e = new ut(o(this.range));
                var t = this._current,
                r = t,
                i = 0,
                s = t,
                u = n.getNodeLength(t);
                n.isAncestorOf(t, this.sc, !0) && (r = this.sc, i = this.so),
                n.isAncestorOf(t, this.ec, !0) && (s = this.ec, u = this.eo),
                st(e, r, i, s, u)
            }
            return new g(e, this.clonePartiallySelectedTextNodes)
        },
        detach: function(e) {
            e && this.range.detach(),
            this.range = this._current = this._next = this._first = this._last = this.sc = this.so = this.ec = this.eo = null
        }
    },
    y.prototype = {
        BAD_BOUNDARYPOINTS_ERR: 1,
        INVALID_NODE_TYPE_ERR: 2
    },
    y.prototype.toString = function() {
        return this.message
    },
    b.prototype = {
        _current: null,
        hasNext: function() {
            return !! this._next
        },
        next: function() {
            return this._current = this._next,
            this._next = this.nodes[++this._position],
            this._current
        },
        detach: function() {
            this._current = this._next = this.nodes = null
        }
    };
    var w = [1, 3, 4, 5, 7, 8, 10],
    E = [2, 9, 11],
    S = [5, 6, 10, 12],
    x = [1, 3, 4, 5, 7, 8, 10, 11],
    T = [1, 3, 4, 5, 7, 8],
    C = n.getRootContainer,
    k = N([9, 11]),
    L = N(S),
    A = N([6, 10, 12]),
    q = document.createElement("style"),
    R = !1;
    try {
        q.innerHTML = "<b>x</b>",
        R = q.firstChild.nodeType == 3
    } catch(U) {}
    e.features.htmlParsingConforms = R;
    var z = R ? 
    function(e) {
        var t = this.startContainer,
        r = n.getDocument(t);
        if (!t) throw new i("INVALID_STATE_ERR");
        var s = null;
        return t.nodeType == 1 ? s = t: n.isCharacterDataNode(t) && (s = n.parentElement(t)),
        s === null || s.nodeName == "HTML" && n.isHtmlNamespace(n.getDocument(s).documentElement) && n.isHtmlNamespace(s) ? s = r.createElement("body") : s = s.cloneNode(!1),
        s.innerHTML = e,
        n.fragmentFromNodeChildren(s)
    }: function(e) {
        M(this);
        var t = o(this),
        r = t.createElement("body");
        return r.innerHTML = e,
        n.fragmentFromNodeChildren(r)
    },
    W = ["startContainer", "startOffset", "endContainer", "endOffset", "collapsed", "commonAncestorContainer"],
    X = 0,
    V = 1,
    $ = 2,
    J = 3,
    K = 0,
    Q = 1,
    G = 2,
    Y = 3;
    Z.prototype = {
        attachListener: function(e, t) {
            this._listeners[e].push(t)
        },
        compareBoundaryPoints: function(e, t) {
            I(this),
            P(this.startContainer, t.startContainer);
            var r,
            i,
            s,
            o,
            u = e == J || e == X ? "start": "end",
            a = e == V || e == X ? "start": "end";
            return r = this[u + "Container"],
            i = this[u + "Offset"],
            s = t[a + "Container"],
            o = t[a + "Offset"],
            n.comparePoints(r, i, s, o)
        },
        insertNode: function(e) {
            I(this),
            _(e, x),
            H(this.startContainer);
            if (n.isAncestorOf(e, this.startContainer, !0)) throw new i("HIERARCHY_REQUEST_ERR");
            var t = l(e, this.startContainer, this.startOffset);
            this.setStartBefore(t)
        },
        cloneContents: function() {
            I(this);
            var e,
            t;
            if (this.collapsed) return o(this).createDocumentFragment();
            if (this.startContainer === this.endContainer && n.isCharacterDataNode(this.startContainer)) return e = this.startContainer.cloneNode(!0),
            e.data = e.data.slice(this.startOffset, this.endOffset),
            t = o(this).createDocumentFragment(),
            t.appendChild(e),
            t;
            var r = new g(this, !0);
            return e = c(r),
            r.detach(),
            e
        },
        canSurroundContents: function() {
            I(this),
            H(this.startContainer),
            H(this.endContainer);
            var e = new g(this, !0),
            t = e._first && s(e._first, this) || e._last && s(e._last, this);
            return e.detach(),
            !t
        },
        surroundContents: function(e) {
            _(e, T);
            if (!this.canSurroundContents()) throw new y("BAD_BOUNDARYPOINTS_ERR");
            var t = this.extractContents();
            if (e.hasChildNodes()) while (e.lastChild) e.removeChild(e.lastChild);
            l(e, this.startContainer, this.startOffset),
            e.appendChild(t),
            this.selectNode(e)
        },
        cloneRange: function() {
            I(this);
            var e = new ut(o(this)),
            t = W.length,
            n;
            while (t--) n = W[t],
            e[n] = this[n];
            return e
        },
        toString: function() {
            I(this);
            var e = this.startContainer;
            if (e === this.endContainer && n.isCharacterDataNode
            (e)) return e.nodeType == 3 || e.nodeType == 4 ? e.data.slice(this.startOffset, this.endOffset) : "";
            var t = [],
            r = new g(this, !0);
            return h(r, 
            function(e) { (e.nodeType == 3 || e.nodeType == 4) && t.push(e.data)
            }),
            r.detach(),
            t.join("")
        },
        compareNode: function(e) {
            I(this);
            var t = e.parentNode,
            r = n.getNodeIndex(e);
            if (!t) throw new i("NOT_FOUND_ERR");
            var s = this.comparePoint(t, r),
            o = this.comparePoint(t, r + 1);
            return s < 0 ? o > 0 ? G: K: o > 0 ? Q: Y
        },
        comparePoint: function(e, t) {
            return I(this),
            B(e, "HIERARCHY_REQUEST_ERR"),
            P(e, this.startContainer),
            n.comparePoints(e, t, this.startContainer, this.startOffset) < 0 ? -1: n.comparePoints(e, t, this.endContainer, this.endOffset) > 0 ? 1: 0
        },
        createContextualFragment: z,
        toHtml: function() {
            I(this);
            var e = o(this).createElement("div");
            return e.appendChild(this.cloneContents()),
            e.innerHTML
        },
        intersectsNode: function(e, t) {
            I(this),
            B(e, "NOT_FOUND_ERR");
            if (n.getDocument(e) !== o(this)) return ! 1;
            var r = e.parentNode,
            i = n.getNodeIndex(e);
            B(r, "NOT_FOUND_ERR");
            var s = n.comparePoints(r, i, this.endContainer, this.endOffset),
            u = n.comparePoints(r, i + 1, this.startContainer, this.startOffset);
            return t ? s <= 0 && u >= 0: s < 0 && u > 0
        },
        isPointInRange: function(e, t) {
            return I(this),
            B(e, "HIERARCHY_REQUEST_ERR"),
            P(e, this.startContainer),
            n.comparePoints(e, t, this.startContainer, this.startOffset) >= 0 && n.comparePoints(e, t, this.endContainer, this.endOffset) <= 0
        },
        intersectsRange: function(e, t) {
            I(this);
            if (o(e) != o(this)) throw new i("WRONG_DOCUMENT_ERR");
            var r = n.comparePoints(this.startContainer, this.startOffset, e.endContainer, e.endOffset),
            s = n.comparePoints(this.endContainer, this.endOffset, e.startContainer, e.startOffset);
            return t ? r <= 0 && s >= 0: r < 0 && s > 0
        },
        intersection: function(e) {
            if (this.intersectsRange(e)) {
                var t = n.comparePoints(this.startContainer, this.startOffset, e.startContainer, e.startOffset),
                r = n.comparePoints(this.endContainer, this.endOffset, e.endContainer, e.endOffset),
                i = this.cloneRange();
                return t == -1 && i.setStart(e.startContainer, e.startOffset),
                r == 1 && i.setEnd(e.endContainer, e.endOffset),
                i
            }
            return null
        },
        union: function(e) {
            if (this.intersectsRange(e, !0)) {
                var t = this.cloneRange();
                return n.comparePoints(e.startContainer, e.startOffset, this.startContainer, this.startOffset) == -1 && t.setStart(e.startContainer, e.startOffset),
                n.comparePoints(e.endContainer, e.endOffset, this.endContainer, this.endOffset) == 1 && t.setEnd(e.endContainer, e.endOffset),
                t
            }
            throw new y("Ranges do not intersect")
        },
        containsNode: function(e, t) {
            return t ? this.intersectsNode(e, !1) : this.compareNode(e) == Y
        },
        containsNodeContents: function(e) {
            return this.comparePoint(e, 0) >= 0 && this.comparePoint(e, n.getNodeLength(e)) <= 0
        },
        containsRange: function(e) {
            return this.intersection(e).equals(e)
        },
        containsNodeText: function(e) {
            var t = this.cloneRange();
            t.selectNode(e);
            var n = t.getNodes([3]);
            if (n.length > 0) {
                t.setStart(n[0], 0);
                var r = n.pop();
                t.setEnd(r, r.length);
                var i = this.containsRange(t);
                return t.detach(),
                i
            }
            return this.containsNodeContents(e)
        },
        createNodeIterator: function(e, t) {
            return I(this),
            new b(this, e, t)
        },
        getNodes: function(e, t) {
            return I(this),
            v(this, e, t)
        },
        getDocument: function() {
            return o(this)
        },
        collapseBefore: function(e) {
            M(this),
            this.setEndBefore(e),
            this.collapse(!1)
        },
        collapseAfter: function(e) {
            M(this),
            this.setStartAfter(e),
            this.collapse(!0)
        },
        getName: function() {
            return "DomRange"
        },
        equals: function(e) {
            return ut.rangesEqual(this, e)
        },
        inspect: function() {
            return m(this)
        }
    },
    rt(ut, st, ot),
    e.rangePrototype = Z.prototype,
    ut.rangeProperties = W,
    ut.RangeIterator = g,
    ut.copyComparisonConstants = tt,
    ut.createPrototypeRange = rt,
    ut.inspect = m,
    ut.getRangeDocument = o,
    ut.rangesEqual = function(e, t) {
        return e.startContainer === t.startContainer && e.startOffset === t.startOffset && e.endContainer === t.endContainer && e.endOffset === t.endOffset
    },
    e.DomRange = ut,
    e.RangeException = y
}),
rangy.createModule("WrappedRange", 
function(e, t) {
    function o(e) {
        var t = e.parentElement(),
        n = e.duplicate();
        n.collapse(!0);
        var i = n.parentElement();
        n = e.duplicate(),
        n.collapse(!1);
        var s = n.parentElement(),
        o = i == s ? i: r.getCommonAncestor(i, s);
        return o == t ? o: r.getCommonAncestor(t, o)
    }
    function u(e) {
        return e.compareEndPoints("StartToEnd", e) == 0
    }
    function a(e, t, n, s) {
        var o = e.duplicate();
        o.collapse(n);
        var u = o.parentElement();
        r.isAncestorOf(t, u, !0) || (u = t);
        if (!u.canHaveHTML) return new i(u.parentNode, r.getNodeIndex(u));
        var a = r.getDocument(u).createElement("span"),
        f,
        l = n ? "StartToStart": "StartToEnd",
        c,
        h,
        p,
        d;
        do u.insertBefore(a, a.previousSibling),
        o.moveToElementText(a);
        while ((f = o.compareEndPoints(l, e)) > 0 && a.previousSibling);
        d = a.nextSibling;
        if (f == -1 && d && r.isCharacterDataNode(d)) {
            o.setEndPoint(n ? "EndToStart": "EndToEnd", e);
            var v;
            if (/[\r\n]/.test(d.data)) {
                var m = o.duplicate(),
                g = m.text.replace(/\r\n/g, "\r").length;
                v = m.moveStart("character", g);
                while ((f = m.compareEndPoints("StartToEnd", m)) == -1) v++,
                m.moveStart("character", 1)
            } else v = o.text.length;
            p = new i(d, v)
        } else c = (s || !n) && a.previousSibling,
        h = (s || n) && a.nextSibling,
        h && r.isCharacterDataNode(h) ? p = new i(h, 0) : c && r.isCharacterDataNode(c) ? p = new i(c, c.length) : p = new i(u, r.getNodeIndex(a));
        return a.parentNode.removeChild(a),
        p
    }
    function f(e, t) {
        var n,
        i,
        s = e.offset,
        o = r.getDocument(e.node),
        u,
        a,
        f = o.body.createTextRange(),
        l = r.isCharacterDataNode(e.node);
        return l ? (n = e.node, i = n.parentNode) : (a = e.node.childNodes, n = s < a.length ? a[s] : null, i = e.node),
        u = o.createElement("span"),
        u.innerHTML = "&#feff;",
        n ? i.insertBefore(u, n) : i.appendChild(u),
        f.moveToElementText(u),
        f.collapse(!t),
        i.removeChild(u),
        l && f[t ? "moveStart": "moveEnd"]("character", s),
        f
    }
    e.requireModules(["DomUtil", "DomRange"]);
    var n,
    r = e.dom,
    i = r.DomPosition,
    s = e.DomRange;
    if (e.features.implementsDomRange && (!e.features.implementsTextRange || !e.config.preferTextRange))(function() {
        function u(e) {
            var t = i.length,
            n;
            while (t--) n = i[t],
            e[n] = e.nativeRange[n]
        }
        function a(e, t, n, r, i) {
            var s = e.startContainer !== t || e.startOffset != n,
            o = e.endContainer !== r || e.endOffset != i;
            if (s || o) e.setEnd(r, i),
            e.setStart(t, n)
        }
        function f(e) {
            e.nativeRange.detach(),
            e.detached = !0;
            var t = i.length,
            n;
            while (t--) n = i[t],
            e[n] = null
        }
        var t,
        i = s.rangeProperties,
        o,
        l;
        n = function(e) {
            if (!e) throw new Error("Range must be specified");
            this.nativeRange = e,
            u(this)
        },
        s.createPrototypeRange(n, a, f),
        t = n.prototype,
        t.selectNode = function(e) {
            this.nativeRange.selectNode(e),
            u(this)
        },
        t.deleteContents = function() {
            this.nativeRange.deleteContents(),
            u(this)
        },
        t.extractContents = function() {
            var e = this.nativeRange.extractContents();
            return u(this),
            e
        },
        t.cloneContents = function() {
            return this.nativeRange.cloneContents()
        },
        t.surroundContents = function(e) {
            this.nativeRange.surroundContents(e),
            u(this)
        },
        t.collapse = function(e) {
            this.nativeRange.collapse(e),
            u(this)
        },
        t.cloneRange = function() {
            return new n(this.nativeRange.cloneRange())
        },
        t.refresh = function() {
            u(this)
        },
        t.toString = function() {
            return this.nativeRange.toString()
        };
        var c = document.createTextNode("test");
        r.getBody(document).appendChild(c);
        var h = document.createRange();
        h.setStart(c, 0),
        h.setEnd(c, 0);
        try {
            h.setStart(c, 1),
            o = !0,
            t.setStart = function(e, t) {
                this.nativeRange.setStart(e, t),
                u(this)
            },
            t.setEnd = function(e, t) {
                this.nativeRange.setEnd(e, t),
                u(this)
            },
            l = function(e) {
                return function(t) {
                    this.nativeRange[e](t),
                    u(this)
                }
            }
        } catch(p) {
            o = !1,
            t.setStart = function(e, t) {
                try {
                    this.nativeRange.setStart(e, t)
                } catch(n) {
                    this.nativeRange.setEnd(e, t),
                    this.nativeRange.setStart(e, t)
                }
                u(this)
            },
            t.setEnd = function(e, t) {
                try {
                    this.nativeRange.setEnd(e, t)
                } catch(n) {
                    this.nativeRange.setStart(e, t),
                    this.nativeRange.setEnd(e, t)
                }
                u(this)
            },
            l = function(e, t) {
                return function(n) {
                    try {
                        this.nativeRange[e](n)
                    } catch(r) {
                        this.nativeRange[t](n),
                        this.nativeRange[e](n)
                    }
                    u(this)
                }
            }
        }
        t.setStartBefore = l("setStartBefore", "setEndBefore"),
        t.setStartAfter = l("setStartAfter", "setEndAfter"),
        t.setEndBefore = l("setEndBefore", "setStartBefore"),
        t.setEndAfter = l("setEndAfter", "setStartAfter"),
        h.selectNodeContents(c),
        h.startContainer == c && h.endContainer == c && h.startOffset == 0 && h.endOffset == c.length ? t.selectNodeContents = function(e) {
            this.nativeRange.selectNodeContents(e),
            u(this)
        }: t.selectNodeContents = function(e) {
            this.setStart(e, 0),
            this.setEnd(e, s.getEndOffset(e))
        },
        h.selectNodeContents(c),
        h.setEnd(c, 3);
        var d = document.createRange();
        d.selectNodeContents(c),
        d.setEnd(c, 4),
        d.setStart(c, 2),
        h.compareBoundaryPoints(h.START_TO_END, d) == -1 & h.compareBoundaryPoints(h.END_TO_START, d) == 1 ? t.compareBoundaryPoints = function(e, t) {
            return t = t.nativeRange || t,
            e == t.START_TO_END ? e = t.END_TO_START: e == t.END_TO_START && (e = t.START_TO_END),
            this.nativeRange.compareBoundaryPoints(e, t)
        }: t.compareBoundaryPoints = function(e, t) {
            return this.nativeRange.compareBoundaryPoints(e, t.nativeRange || t)
        },
        e.util.isHostMethod(h, "createContextualFragment") && (t.createContextualFragment = function(e) {
            return this.nativeRange.createContextualFragment(e)
        }),
        r.getBody(document).removeChild(c),
        h.detach(),
        d.detach()
    })(),
    e.createNativeRange = function(e) {
        return e = e || document,
        e.createRange()
    };
    else if (e.features.implementsTextRange) {
        n = function(e) {
            this.textRange = e,
            this.refresh()
        },
        n.prototype = new s(document),
        n.prototype.refresh = function() {
            var e,
            t,
            n = o(this.textRange);
            u(this.textRange) ? t = e = a(this.textRange, n, !0, !0) : (e = a(this.textRange, n, !0, !1), t = a(this.textRange, n, !1, !1)),
            this.setStart(e.node, e.offset),
            this.setEnd(t.node, t.offset)
        },
        s.copyComparisonConstants(n);
        var l = function() {
            return this
        } ();
        typeof l.Range == "undefined" && (l.Range = n),
        e.createNativeRange = function(e) {
            return e = e || document,
            e.body.createTextRange()
        }
    }
    e.features.implementsTextRange && (n.rangeToTextRange = function(e) {
        if (e.collapsed) {
            var t = f(new i(e.startContainer, e.startOffset), !0);
            return t
        }
        var n = f(new i(e.startContainer, e.startOffset), !0),
        s = f(new i(e.endContainer, e.endOffset), !1),
        o = r.getDocument(e.startContainer).body.createTextRange();
        return o.setEndPoint("StartToStart", n),
        o.setEndPoint("EndToEnd", s),
        o
    }),
    n.prototype.getName = function() {
        return "WrappedRange"
    },
    e.WrappedRange = n,
    e.createRange = function(t) {
        return t = t || document,
        new n(e.createNativeRange(t))
    },
    e.createRangyRange = function(e) {
        return e = e || document,
        new s(e)
    },
    e.createIframeRange = function(t) {
        return e.createRange(r.getIframeDocument(t))
    },
    e.createIframeRangyRange = function(t) {
        return e.createRangyRange(r.getIframeDocument(t))
    },
    e.addCreateMissingNativeApiListener(function(t) {
        var n = t.document;
        typeof n.createRange == "undefined" && (n.createRange = function() {
            return e.createRange(this)
        }),
        n = t = null
    })
}),
rangy.createModule("WrappedSelection", 
function(e, t) {
    function p(e) {
        return (e || window).getSelection()
    }
    function d(e) {
        return (e || window).document.selection
    }
    function L(e, t, n) {
        var r = n ? "end": "start",
        i = n ? "start": "end";
        e.anchorNode = t[r + "Container"],
        e.anchorOffset = t[r + "Offset"],
        e.focusNode = t[i + "Container"],
        e.focusOffset = t[i + "Offset"]
    }
    function A(e) {
        var t = e.nativeSelection;
        e.anchorNode = t.anchorNode,
        e.anchorOffset = t.anchorOffset,
        e.focusNode = t.focusNode,
        e.focusOffset = t.focusOffset
    }
    function O(e) {
        e.anchorNode = e.focusNode = null,
        e.anchorOffset = e.focusOffset = 0,
        e.rangeCount = 0,
        e.isCollapsed = !0,
        e._ranges.length = 0
    }
    function M(t) {
        var n;
        return t instanceof o ? (n = t._selectionNativeRange, n || (n = e.createNativeRange(i.getDocument(t.startContainer)), n.setEnd(t.endContainer, t.endOffset), n.setStart(t.startContainer, t.startOffset), t._selectionNativeRange = n, t.attachListener("detach", 
        function() {
            this._selectionNativeRange = null
        }))) : t instanceof u ? n = t.nativeRange: e.features.implementsDomRange && t instanceof i.getWindow(t.startContainer).Range && (n = t),
        n
    }
    function _(e) {
        if (!e.length || e[0].nodeType != 1) return ! 1;
        for (var t = 1, n = e.length; t < n; ++t) if (!i.isAncestorOf(e[0], e[t])) return ! 1;
        return ! 0
    }
    function D(e) {
        var t = e.getNodes();
        if (!_(t)) throw new Error("getSingleElementFromRange: range " + e.inspect() + " did not consist of a single element");
        return t[0]
    }
    function P(e) {
        return !! e && typeof e.text != "undefined"
    }
    function H(e, t) {
        var n = new u(t);
        e._ranges = [n],
        L(e, n, !1),
        e.rangeCount = 1,
        e.isCollapsed = n.collapsed
    }
    function B(t) {
        t._ranges.length = 0;
        if (t.docSelection.type == "None") O(t);
        else {
            var n = t.docSelection.createRange();
            if (P(n)) H(t, n);
            else {
                t.rangeCount = n.length;
                var r,
                s = i.getDocument(n.item(0));
                for (var o = 0; o < t.rangeCount; ++o) r = e.createRange(s),
                r.selectNode(n.item(o)),
                t._ranges.push(r);
                t.isCollapsed = t.rangeCount == 1 && t._ranges[0].collapsed,
                L(t, t._ranges[t.rangeCount - 1], !1)
            }
        }
    }
    function j(e, t) {
        var n = e.docSelection.createRange(),
        r = D(t),
        s = i.getDocument(n.item(0)),
        o = i.getBody(s).createControlRange();
        for (var u = 0, a = n.length; u < a; ++u) o.add(n.item(u));
        try {
            o.add(r)
        } catch(f) {
            throw new Error("addRange(): Element within the specified Range could not be added to control selection (does it have layout?)")
        }
        o.select(),
        B(e)
    }
    function I(e, t, n) {
        this.nativeSelection = e,
        this.docSelection = t,
        this._ranges = [],
        this.win = n,
        this.refresh()
    }
    function R(e, t) {
        var n = i.getDocument(t[0].startContainer),
        r = i.getBody(n).createControlRange();
        for (var s = 0, o; s < rangeCount; ++s) {
            o = D(t[s]);
            try {
                r.add(o)
            } catch(u) {
                throw new Error("setRanges(): Element within the one of the specified Ranges could not be added to control selection (does it have layout?)")
            }
        }
        r.select(),
        B(e)
    }
    function V(e, t) {
        if (e.anchorNode && i.getDocument(e.anchorNode) !== i.getDocument(t)) throw new a("WRONG_DOCUMENT_ERR")
    }
    function $(e) {
        var t = [],
        n = new f(e.anchorNode, e.anchorOffset),
        r = new f(e.focusNode, e.focusOffset),
        i = typeof e.getName == "function" ? e.getName() : "Selection";
        if (typeof e.rangeCount != "undefined") for (var s = 0, u = e.rangeCount; s < u; ++s) t[s] = o.inspect(e.getRangeAt(s));
        return "[" + i + "(Ranges: " + t.join(", ") + ")(anchor: " + n.inspect() + ", focus: " + r.inspect() + "]"
    }
    e.requireModules(["DomUtil", "DomRange", "WrappedRange"]),
    e.config.checkSelectionRanges = !0;
    var n = "boolean",
    r = "_rangySelection",
    i = e.dom,
    s = e.util,
    o = e.DomRange,
    u = e.WrappedRange,
    a = e.DOMException,
    f = i.DomPosition,
    l,
    c,
    h = "Control",
    v = e.util.isHostMethod(window, "getSelection"),
    m = e.util.isHostObject(document, "selection"),
    g = m && (!v || e.config.preferTextRange);
    g ? (l = d, e.isSelectionValid = function(e) {
        var t = (e || window).document,
        n = t.selection;
        return n.type != "None" || i.getDocument(n.createRange().parentElement()) == t
    }) : v ? (l = p, e.isSelectionValid = function() {
        return ! 0
    }) : t.fail("Neither document.selection or window.getSelection() detected."),
    e.getNativeSelection = l;
    var y = l(),
    b = e.createNativeRange(document),
    w = i.getBody(document),
    E = s.areHostObjects(y, ["anchorNode", "focusNode"] && s.areHostProperties(y, ["anchorOffset", "focusOffset"]));
    e.features.selectionHasAnchorAndFocus = E;
    var S = s.isHostMethod(y, "extend");
    e.features.selectionHasExtend = S;
    var x = typeof y.rangeCount == "number";
    e.features.selectionHasRangeCount = x;
    var T = !1,
    N = !0;
    s.areHostMethods(y, ["addRange", "getRangeAt", "removeAllRanges"]) && typeof y.rangeCount == "number" && e.features.implementsDomRange && 
    function() {
        var e = document.createElement("iframe");
        w.appendChild(e);
        var t = i.getIframeDocument(e);
        t.open(),
        t.write("<html><head></head><body>12</body></html>"),
        t.close();
        var n = i.getIframeWindow(e).getSelection(),
        r = t.documentElement,
        s = r.lastChild,
        o = s.firstChild,
        u = t.createRange();
        u.setStart(o, 1),
        u.collapse(!0),
        n.addRange(u),
        N = n.rangeCount == 1,
        n.removeAllRanges();
        var a = u.cloneRange();
        u.setStart(o, 0),
        a.setEnd(o, 2),
        n.addRange(u),
        n.addRange(a),
        T = n.rangeCount == 2,
        u.detach(),
        a.detach(),
        w.removeChild(e)
    } (),
    e.features.selectionSupportsMultipleRanges = T,
    e.features.collapsedNonEditableSelectionsSupported = N;
    var C = !1,
    k;
    w && s.isHostMethod(w, "createControlRange") && (k = w.createControlRange(), s.areHostProperties(k, ["item", "add"]) && (C = !0)),
    e.features.implementsControlRange = C,
    E ? c = function(e) {
        return e.anchorNode === e.focusNode && e.anchorOffset === e.focusOffset
    }: c = function(e) {
        return e.rangeCount ? e.getRangeAt(e.rangeCount - 1).collapsed: !1
    };
    var F;
    s.isHostMethod(y, "getRangeAt") ? F = function(e, t) {
        try {
            return e.getRangeAt(t)
        } catch(n) {
            return null
        }
    }: E && (F = function(t) {
        var n = i.getDocument(t.anchorNode),
        r = e.createRange(n);
        return r.setStart(t.anchorNode, t.anchorOffset),
        r.setEnd(t.focusNode, t.focusOffset),
        r.collapsed !== this.isCollapsed && (r.setStart(t.focusNode, t.focusOffset), r.setEnd(t.anchorNode, t.anchorOffset)),
        r
    }),
    e.getSelection = function(e) {
        e = e || window;
        var t = e[r],
        n = l(e),
        i = m ? d(e) : null;
        return t ? (t.nativeSelection = n, t.docSelection = i, t.refresh(e)) : (t = new I(n, i, e), e[r] = t),
        t
    },
    e.getIframeSelection = function(t) {
        return e.getSelection(i.getIframeWindow(t))
    };
    var q = I.prototype;
    if (!g && E && s.areHostMethods(y, ["removeAllRanges", "addRange"])) {
        q.removeAllRanges = function() {
            this.nativeSelection.removeAllRanges(),
            O(this)
        };
        var U = function(t, n) {
            var r = o.getRangeDocument(n),
            i = e.createRange(r);
            i.collapseToPoint(n.endContainer, n.endOffset),
            t.nativeSelection.addRange(M(i)),
            t.nativeSelection.extend(n.startContainer, n.startOffset),
            t.refresh()
        };
        x ? q.addRange = function(t, n) {
            if (C && m && this.docSelection.type == h) j(this, t);
            else if (n && S) U(this, t);
            else {
                var r;
                T ? r = this.rangeCount: (this.removeAllRanges(), r = 0),
                this.nativeSelection.addRange(M(t)),
                this.rangeCount = this.nativeSelection.rangeCount;
                if (this.rangeCount == r + 1) {
                    if (e.config.checkSelectionRanges) {
                        var i = F(this.nativeSelection, this.rangeCount - 1);
                        i && !o.rangesEqual(i, t) && (t = new u(i))
                    }
                    this._ranges[this.rangeCount - 1] = t,
                    L(this, t, X(this.nativeSelection)),
                    this.isCollapsed = c(this)
                } else this.refresh()
            }
        }: q.addRange = function(e, t) {
            t && S ? U(this, e) : (this.nativeSelection.addRange(M(e)), this.refresh())
        },
        q.setRanges = function(e) {
            if (C && e.length > 1) R(this, e);
            else {
                this.removeAllRanges();
                for (var t = 0, n = e.length; t < n; ++t) this.addRange(e[t])
            }
        }
    } else {
        if (! (s.isHostMethod(y, "empty") && s.isHostMethod(b, "select") && C && g)) return t.fail("No means of selecting a Range or TextRange was found"),
        !1;
        q.removeAllRanges = function() {
            try {
                this.docSelection.empty();
                if (this.docSelection.type != "None") {
                    var e;
                    if (this.anchorNode) e = i.getDocument(this.anchorNode);
                    else if (this.docSelection.type == h) {
                        var t = this.docSelection.createRange();
                        t.length && (e = i.getDocument(t.item(0)).body.createTextRange())
                    }
                    if (e) {
                        var n = e.body.createTextRange();
                        n.select(),
                        this.docSelection.empty()
                    }
                }
            } catch(r) {}
            O(this)
        },
        q.addRange = function(e) {
            this.docSelection.type == h ? j(this, e) : (u.rangeToTextRange(e).select(), this._ranges[0] = e, this.rangeCount = 1, this.isCollapsed = this._ranges[0].collapsed, L(this, e, !1))
        },
        q.setRanges = function(e) {
            this.removeAllRanges();
            var t = e.length;
            t > 1 ? R(this, e) : t && this.addRange(e[0])
        }
    }
    q.getRangeAt = function(e) {
        if (e < 0 || e >= this.rangeCount) throw new a("INDEX_SIZE_ERR");
        return this._ranges[e]
    };
    var z;
    if (g) z = function(t) {
        var n;
        e.isSelectionValid(t.win) ? n = t.docSelection.createRange() : (n = i.getBody(t.win.document).createTextRange(), n.collapse(!0)),
        t.docSelection.type == h ? B(t) : P(n) ? H(t, n) : O(t)
    };
    else if (s.isHostMethod(y, "getRangeAt") && typeof y.rangeCount == "number") z = function(t) {
        if (C && m && t.docSelection.type == h) B(t);
        else {
            t._ranges.length = t.rangeCount = t.nativeSelection.rangeCount;
            if (t.rangeCount) {
                for (var n = 0, r = t.rangeCount; n < r; ++n) t._ranges[n] = new e.WrappedRange(t.nativeSelection.getRangeAt(n));
                L(t, t._ranges[t.rangeCount - 1], X(t.nativeSelection)),
                t.isCollapsed = c(t)
            } else O(t)
        }
    };
    else {
        if (!E || typeof y.isCollapsed != n || typeof b.collapsed != n || !e.features.implementsDomRange) return t.fail("No means of obtaining a Range or TextRange from the user's selection was found"),
        !1;
        z = function(e) {
            var t,
            n = e.nativeSelection;
            n.anchorNode ? (t = F(n, 0), e._ranges = [t], e.rangeCount = 1, A(e), e.isCollapsed = c(e)) : O(e)
        }
    }
    q.refresh = function(e) {
        var t = e ? this._ranges.slice(0) : null;
        z(this);
        if (e) {
            var n = t.length;
            if (n != this._ranges.length) return ! 1;
            while (n--) if (!o.rangesEqual(t[n], this._ranges[n])) return ! 1;
            return ! 0
        }
    };
    var W = function(e, t) {
        var n = e.getAllRanges(),
        r = !1;
        e.removeAllRanges();
        for (var i = 0, s = n.length; i < s; ++i) r || t !== n[i] ? e.addRange(n[i]) : r = !0;
        e.rangeCount || O(e)
    };
    C ? q.removeRange = function(e) {
        if (this.docSelection.type == h) {
            var t = this.docSelection.createRange(),
            n = D(e),
            r = i.getDocument(t.item(0)),
            s = i.getBody(r).createControlRange(),
            o,
            u = !1;
            for (var a = 0, f = t.length; a < f; ++a) o = t.item(a),
            o !== n || u ? s.add(t.item(a)) : u = !0;
            s.select(),
            B(this)
        } else W(this, e)
    }: q.removeRange = function(e) {
        W(this, e)
    };
    var X; ! g && E && e.features.implementsDomRange ? (X = function(e) {
        var t = !1;
        return e.anchorNode && (t = i.comparePoints(e.anchorNode, e.anchorOffset, e.focusNode, e.focusOffset) == 1),
        t
    },
    q.isBackwards = function() {
        return X(this)
    }) : X = q.isBackwards = function() {
        return ! 1
    },
    q.toString = function() {
        var e = [];
        for (var t = 0, n = this.rangeCount; t < n; ++t) e[t] = "" + this._ranges[t];
        return e.join("")
    },
    q.collapse = function(t, n) {
        V(this, t);
        var r = e.createRange(i.getDocument(t));
        r.collapseToPoint(t, n),
        this.removeAllRanges(),
        this.addRange(r),
        this.isCollapsed = !0
    },
    q.collapseToStart = function() {
        if (!this.rangeCount) throw new a("INVALID_STATE_ERR");
        var e = this._ranges[0];
        this.collapse(e.startContainer, e.startOffset)
    },
    q.collapseToEnd = function() {
        if (!this.rangeCount) throw new a("INVALID_STATE_ERR");
        var e = this._ranges[this.rangeCount - 1];
        this.collapse(e.endContainer, e.endOffset)
    },
    q.selectAllChildren = function(t) {
        V(this, t);
        var n = e.createRange(i.getDocument(t));
        n.selectNodeContents(t),
        this.removeAllRanges(),
        this.addRange(n)
    },
    q.deleteFromDocument = function() {
        if (C && m && this.docSelection.type == h) {
            var e = this.docSelection.createRange(),
            t;
            while (e.length) t = e.item(0),
            e.remove(t),
            t.parentNode.removeChild(t);
            this.refresh()
        } else if (this.rangeCount) {
            var n = this.getAllRanges();
            this.removeAllRanges();
            for (var r = 0, i = n.length; r < i; ++r) n[r].deleteContents();
            this.addRange(n[i - 1])
        }
    },
    q.getAllRanges = function() {
        return this._ranges.slice(0)
    },
    q.setSingleRange = function(e) {
        this.setRanges([e])
    },
    q.containsNode = function(e, t) {
        for (var n = 0, r = this._ranges.length; n < r; ++n) if (this._ranges[n].containsNode(e, t)) return ! 0;
        return ! 1
    },
    q.toHtml = function() {
        var e = "";
        if (this.rangeCount) {
            var t = o.getRangeDocument(this._ranges[0]).createElement("div");
            for (var n = 0, r = this._ranges.length; n < r; ++n) t.appendChild(this._ranges[n].cloneContents());
            e = t.innerHTML
        }
        return e
    },
    q.getName = function() {
        return "WrappedSelection"
    },
    q.inspect = function() {
        return $(this)
    },
    q.detach = function() {
        this.win[r] = null,
        this.win = this.anchorNode = this.focusNode = null
    },
    I.inspect = $,
    e.Selection = I,
    e.selectionPrototype = q,
    e.addCreateMissingNativeApiListener(function(t) {
        typeof t.getSelection == "undefined" && (t.getSelection = function() {
            return e.getSelection(this)
        }),
        t = null
    })
});
var Base = function() {};
Base.extend = function(e, t) {
    var n = Base.prototype.extend;
    Base._prototyping = !0;
    var r = new this;
    n.call(r, e),
    r.base = function() {},
    delete Base._prototyping;
    var i = r.constructor,
    s = r.constructor = function() {
        if (!Base._prototyping) if (this._constructing || this.constructor == s) this._constructing = !0,
        i.apply(this, arguments),
        delete this._constructing;
        else if (arguments[0] != null) return (arguments[0].extend || n).call(arguments[0], r)
    };
    return s.ancestor = this,
    s.extend = this.extend,
    s.forEach = this.forEach,
    s.implement = this.implement,
    s.prototype = r,
    s.toString = this.toString,
    s.valueOf = function(e) {
        return e == "object" ? s: i.valueOf()
    },
    n.call(s, t),
    typeof s.init == "function" && s.init(),
    s
},
Base.prototype = {
    extend: function(e, t) {
        if (arguments.length > 1) {
            var n = this[e];
            if (n && typeof t == "function" && (!n.valueOf || n.valueOf() != t.valueOf()) && /\bbase\b/.test(t)) {
                var r = t.valueOf();
                t = function() {
                    var e = this.base || Base.prototype.base;
                    this.base = n;
                    var t = r.apply(this, arguments);
                    return this.base = e,
                    t
                },
                t.valueOf = function(e) {
                    return e == "object" ? t: r
                },
                t.toString = Base.toString
            }
            this[e] = t
        } else if (e) {
            var i = Base.prototype.extend; ! Base._prototyping && typeof this != "function" && (i = this.extend || i);
            var s = {
                toSource: null
            },
            o = ["constructor", "toString", "valueOf"],
            u = Base._prototyping ? 0: 1;
            while (a = o[u++]) e[a] != s[a] && i.call(this, a, e[a]);
            for (var a in e) s[a] || i.call(this, a, e[a])
        }
        return this
    }
},
Base = Base.extend({
    constructor: function() {
        this.extend(arguments[0])
    }
},
{
    ancestor: Object,
    version: "1.1",
    forEach: function(e, t, n) {
        for (var r in e) this.prototype[r] === undefined && t.call(n, e[r], r, e)
    },
    implement: function() {
        for (var e = 0; e < arguments.length; e++) typeof arguments[e] == "function" ? arguments[e](this.prototype) : this.prototype.extend(arguments[e]);
        return this
    },
    toString: function() {
        return String(this.valueOf())
    }
}),
wysihtml5.browser = function() {
    function u(e) {
        return (/ipad|iphone|ipod/.test(e) && e.match(/ os (\d+).+? like mac os x/) || [, 0])[1]
    }
    var e = navigator.userAgent,
    t = document.createElement("div"),
    n = e.indexOf("MSIE") !== -1 && e.indexOf("Opera") === -1,
    r = e.indexOf("Gecko") !== -1 && e.indexOf("KHTML") === -1,
    i = e.indexOf("AppleWebKit/") !== -1,
    s = e.indexOf("Chrome/") !== -1,
    o = e.indexOf("Opera/") !== -1;
    return {
        USER_AGENT: e,
        supported: function() {
            var e = this.USER_AGENT.toLowerCase(),
            n = "contentEditable" in t,
            r = document.execCommand && document.queryCommandSupported && document.queryCommandState,
            i = document.querySelector && document.querySelectorAll,
            s = this.isIos() && u(e) < 5 || e.indexOf("opera mobi") !== -1 || e.indexOf("hpwos/") !== -1;
            return n && r && i && !s
        },
        isTouchDevice: function() {
            return this.supportsEvent("touchmove")
        },
        isIos: function() {
            var e = this.USER_AGENT.toLowerCase();
            return e.indexOf("webkit") !== -1 && e.indexOf("mobile") !== -1
        },
        supportsSandboxedIframes: function() {
            return n
        },
        throwsMixedContentWarningWhenIframeSrcIsEmpty: function() {
            return ! ("querySelector" in document)
        },
        displaysCaretInEmptyContentEditableCorrectly: function() {
            return ! r
        },
        hasCurrentStyleProperty: function() {
            return "currentStyle" in t
        },
        insertsLineBreaksOnReturn: function() {
            return r
        },
        supportsPlaceholderAttributeOn: function(e) {
            return "placeholder" in e
        },
        supportsEvent: function(e) {
            return "on" + e in t || 
            function() {
                return t.setAttribute("on" + e, "return;"),
                typeof t["on" + e] == "function"
            } ()
        },
        supportsEventsInIframeCorrectly: function() {
            return ! o
        },
        firesOnDropOnlyWhenOnDragOverIsCancelled: function() {
            return i || r
        },
        supportsDataTransfer: function() {
            try {
                return i && (window.Clipboard || window.DataTransfer).prototype.getData
            } catch(e) {
                return ! 1
            }
        },
        supportsHTML5Tags: function(e) {
            var t = e.createElement("div"),
            n = "<article>foo</article>";
            return t.innerHTML = n,
            t.innerHTML.toLowerCase() === n
        },
        supportsCommand: function() {
            var e = {
                formatBlock: n,
                insertUnorderedList: n || o || i,
                insertOrderedList: n || o || i
            },
            t = {
                insertHTML: r
            };
            return function(n, r) {
                var i = e[r];
                if (!i) {
                    try {
                        return n.queryCommandSupported(r)
                    } catch(s) {}
                    try {
                        return n.queryCommandEnabled(r)
                    } catch(o) {
                        return !! t[r]
                    }
                }
                return ! 1
            }
        } (),
        doesAutoLinkingInContentEditable: function() {
            return n
        },
        canDisableAutoLinking: function() {
            return this.supportsCommand(document, "AutoUrlDetect")
        },
        clearsContentEditableCorrectly: function() {
            return r || o || i
        },
        supportsGetAttributeCorrectly: function() {
            var e = document.createElement("td");
            return e.getAttribute("rowspan") != "1"
        },
        canSelectImagesInContentEditable: function() {
            return r || n || o
        },
        clearsListsInContentEditableCorrectly: function() {
            return r || n || i
        },
        autoScrollsToCaret: function() {
            return ! i
        },
        autoClosesUnclosedTags: function() {
            var e = t.cloneNode(!1),
            n,
            r;
            return e.innerHTML = "<p><div></div>",
            r = e.innerHTML.toLowerCase(),
            n = r === "<p></p><div></div>" || r === "<p><div></div></p>",
            this.autoClosesUnclosedTags = function() {
                return n
            },
            n
        },
        supportsNativeGetElementsByClassName: function() {
            return String(document.getElementsByClassName).indexOf("[native code]") !== -1
        },
        supportsSelectionModify: function() {
            return "getSelection" in window && "modify" in window.getSelection()
        },
        supportsClassList: function() {
            return "classList" in t
        },
        needsSpaceAfterLineBreak: function() {
            return o
        },
        supportsSpeechApiOn: function(t) {
            var n = e.match(/Chrome\/(\d+)/) || [, 0];
            return n[1] >= 11 && ("onwebkitspeechchange" in t || "speech" in t)
        },
        crashesWhenDefineProperty: function(e) {
            return n && (e === "XMLHttpRequest" || e === "XDomainRequest")
        },
        doesAsyncFocus: function() {
            return n
        },
        hasProblemsSettingCaretAfterImg: function() {
            return n
        },
        hasUndoInContextMenu: function() {
            return r || s || o
        }
    }
} (),
wysihtml5.lang.array = function(e) {
    return {
        contains: function(t) {
            if (e.indexOf) return e.indexOf(t) !== -1;
            for (var n = 0, r = e.length; n < r; n++) if (e[n] === t) return ! 0;
            return ! 1
        },
        without: function(t) {
            t = wysihtml5.lang.array(t);
            var n = [],
            r = 0,
            i = e.length;
            for (; r < i; r++) t.contains(e[r]) || n.push(e[r]);
            return n
        },
        get: function() {
            var t = 0,
            n = e.length,
            r = [];
            for (; t < n; t++) r.push(e[t]);
            return r
        }
    }
},
wysihtml5.lang.Dispatcher = Base.extend({
    observe: function(e, t) {
        return this.events = this.events || {},
        this.events[e] = this.events[e] || [],
        this.events[e].push(t),
        this
    },
    on: function() {
        return this.observe.apply(this, wysihtml5.lang.array(arguments).get())
    },
    fire: function(e, t) {
        this.events = this.events || {};
        var n = this.events[e] || [],
        r = 0;
        for (; r < n.length; r++) n[r].call(this, t);
        return this
    },
    stopObserving: function(e, t) {
        this.events = this.events || {};
        var n = 0,
        r,
        i;
        if (e) {
            r = this.events[e] || [],
            i = [];
            for (; n < r.length; n++) r[n] !== t && t && i.push(r[n]);
            this.events[e] = i
        } else this.events = {};
        return this
    }
}),
wysihtml5.lang.object = function(e) {
    return {
        merge: function(t) {
            for (var n in t) e[n] = t[n];
            return this
        },
        get: function() {
            return e
        },
        clone: function() {
            var t = {},
            n;
            for (n in e) t[n] = e[n];
            return t
        },
        isArray: function() {
            return Object.prototype.toString.call(e) === "[object Array]"
        }
    }
},
function() {
    var e = /^\s+/,
    t = /\s+$/;
    wysihtml5.lang.string = function(n) {
        return n = String(n),
        {
            trim: function() {
                return n.replace(e, "").replace(t, "")
            },
            interpolate: function(e) {
                for (var t in e) n = this.replace("#{" + t + "}").by(e[t]);
                return n
            },
            replace: function(e) {
                return {
                    by: function(t) {
                        return n.split(e).join(t)
                    }
                }
            }
        }
    }
} (),
function(e) {
    function o(e) {
        return l(e) ? e: (e === e.ownerDocument.documentElement && (e = e.ownerDocument.body), c(e))
    }
    function u(e) {
        return e.replace(n, 
        function(e, t) {
            var n = (t.match(r) || [])[1] || "",
            o = s[n];
            t = t.replace(r, ""),
            t.split(o).length > t.split(n).length && (t += n, n = "");
            var u = t,
            a = t;
            return t.length > i && (a = a.substr(0, i) + "..."),
            u.substr(0, 4) === "www." && (u = "http://" + u),
            '<a href="' + u + '">' + a + "</a>" + n
        })
    }
    function a(e) {
        var t = e._wysihtml5_tempElement;
        return t || (t = e._wysihtml5_tempElement = e.createElement("div")),
        t
    }
    function f(e) {
        var t = e.parentNode,
        n = a(t.ownerDocument);
        n.innerHTML = "<span></span>" + u(e.data),
        n.removeChild(n.firstChild);
        while (n.firstChild) t.insertBefore(n.firstChild, e);
        t.removeChild(e)
    }
    function l(e) {
        var n;
        while (e.parentNode) {
            e = e.parentNode,
            n = e.nodeName;
            if (t.contains(n)) return ! 0;
            if (n === "body") return ! 1
        }
        return ! 1
    }
    function c(r) {
        if (t.contains(r.nodeName)) return;
        if (r.nodeType === e.TEXT_NODE && r.data.match(n)) {
            f(r);
            return
        }
        var i = e.lang.array(r.childNodes).get(),
        s = i.length,
        o = 0;
        for (; o < s; o++) c(i[o]);
        return r
    }
    var t = e.lang.array(["CODE", "PRE", "A", "SCRIPT", "HEAD", "TITLE", "STYLE"]),
    n = /((https?:\/\/|www\.)[^\s<]{3,})/gi,
    r = /([^\w\/\-](,?))$/i,
    i = 9999,
    s = {
        ")": "(",
        "]": "[",
        "}": "{"
    };
    e.dom.autoLink = o,
    e.dom.autoLink.URL_REG_EXP = n
} (wysihtml5),
function(e) {
    var t = e.browser.supportsClassList(),
    n = e.dom;
    n.addClass = function(e, r) {
        if (t) return e.classList.add(r);
        if (n.hasClass(e, r)) return;
        e.className += " " + r
    },
    n.removeClass = function(e, n) {
        if (t) return e.classList.remove(n);
        e.className = e.className.replace(new RegExp("(^|\\s+)" + n + "(\\s+|$)"), " ")
    },
    n.hasClass = function(e, n) {
        if (t) return e.classList.contains(n);
        var r = e.className;
        return r.length > 0 && (r == n || (new RegExp("(^|\\s)" + n + "(\\s|$)")).test(r))
    }
} (wysihtml5),
wysihtml5.dom.contains = function() {
    var e = document.documentElement;
    if (e.contains) return function(e, t) {
        return t.nodeType !== wysihtml5.ELEMENT_NODE && (t = t.parentNode),
        e !== t && e.contains(t)
    };
    if (e.compareDocumentPosition) return function(e, t) {
        return !! (e.compareDocumentPosition(t) & 16)
    }
} (),
wysihtml5.dom.convertToList = function() {
    function e(e, t) {
        var n = e.createElement("li");
        return t.appendChild(n),
        n
    }
    function t(e, t) {
        return e.createElement(t)
    }
    function n(n, r) {
        if (n.nodeName === "UL" || n.nodeName === "OL" || n.nodeName === "MENU") return n;
        var i = n.ownerDocument,
        s = t(i, r),
        o = n.querySelectorAll("br"),
        u = o.length,
        a,
        f,
        l,
        c,
        h,
        p,
        d,
        v,
        m;
        for (m = 0; m < u; m++) {
            c = o[m];
            while ((h = c.parentNode) && h !== n && h.lastChild === c) {
                if (wysihtml5.dom.getStyle("display").from(h) === "block") {
                    h.removeChild(c);
                    break
                }
                wysihtml5.dom.insert(c).after(c.parentNode)
            }
        }
        a = wysihtml5.lang.array(n.childNodes).get(),
        f = a.length;
        for (m = 0; m < f; m++) {
            v = v || e(i, s),
            l = a[m],
            p = wysihtml5.dom.getStyle("display").from(l) === "block",
            d = l.nodeName === "BR";
            if (p) {
                v = v.firstChild ? e(i, s) : v,
                v.appendChild(l),
                v = null;
                continue
            }
            if (d) {
                v = v.firstChild ? null: v;
                continue
            }
            v.appendChild(l)
        }
        return n.parentNode.replaceChild(s, n),
        s
    }
    return n
} (),
wysihtml5.dom.copyAttributes = function(e) {
    return {
        from: function(t) {
            return {
                to: function(n) {
                    var r,
                    i = 0,
                    s = e.length;
                    for (; i < s; i++) r = e[i],
                    typeof t[r] != "undefined" && t[r] !== "" && (n[r] = t[r]);
                    return {
                        andTo: arguments.callee
                    }
                }
            }
        }
    }
},
function(e) {
    var t = ["-webkit-box-sizing", "-moz-box-sizing", "-ms-box-sizing", "box-sizing"],
    n = function(t) {
        return r(t) ? parseInt(e.getStyle("width").from(t), 10) < t.offsetWidth: !1
    },
    r = function(n) {
        var r = 0,
        i = t.length;
        for (; r < i; r++) if (e.getStyle(t[r]).from(n) === "border-box") return t[r]
    };
    e.copyStyles = function(r) {
        return {
            from: function(i) {
                n(i) && (r = wysihtml5.lang.array(r).without(t));
                var s = "",
                o = r.length,
                u = 0,
                a;
                for (; u < o; u++) a = r[u],
                s += a + ":" + e.getStyle(a).from(i) + ";";
                return {
                    to: function(t) {
                        return e.setStyles(s).on(t),
                        {
                            andTo: arguments.callee
                        }
                    }
                }
            }
        }
    }
} (wysihtml5.dom),
function(e) {
    e.dom.delegate = function(t, n, r, i) {
        return e.dom.observe(t, r, 
        function(r) {
            var s = r.target,
            o = e.lang.array(t.querySelectorAll(n));
            while (s && s !== t) {
                if (o.contains(s)) {
                    i.call(s, r);
                    break
                }
                s = s.parentNode
            }
        })
    }
} (wysihtml5),
wysihtml5.dom.getAsDom = function() {
    var e = function(e, t) {
        var n = t.createElement("div");
        n.style.display = "none",
        t.body.appendChild(n);
        try {
            n.innerHTML = e
        } catch(r) {}
        return t.body.removeChild(n),
        n
    },
    t = function(e) {
        if (e._wysihtml5_supportsHTML5Tags) return;
        for (var t = 0, r = n.length; t < r; t++) e.createElement(n[t]);
        e._wysihtml5_supportsHTML5Tags = !0
    },
    n = ["abbr", "article", "aside", "audio", "bdi", "canvas", "command", "datalist", "details", "figcaption", "figure", "footer", "header", "hgroup", "keygen", "mark", "meter", "nav", "output", "progress", "rp", "rt", "ruby", "svg", "section", "source", "summary", "time", "track", "video", "wbr"];
    return function(n, r) {
        r = r || document;
        var i;
        return typeof n == "object" && n.nodeType ? (i = r.createElement("div"), i.appendChild(n)) : wysihtml5.browser.supportsHTML5Tags(r) ? (i = r.createElement("div"), i.innerHTML = n) : (t(r), i = e(n, r)),
        i
    }
} (),
wysihtml5.dom.getParentElement = function() {
    function e(e, t) {
        return ! t || !t.length ? !0: typeof t == "string" ? e === t: wysihtml5
        .lang.array(t).contains(e)
    }
    function t(e) {
        return e.nodeType === wysihtml5.ELEMENT_NODE
    }
    function n(e, t, n) {
        var r = (e.className || "").match(n) || [];
        return t ? r[r.length - 1] === t: !!r.length
    }
    function r(t, n, r) {
        while (r--&&t && t.nodeName !== "BODY") {
            if (e(t.nodeName, n)) return t;
            t = t.parentNode
        }
        return null
    }
    function i(r, i, s, o, u) {
        while (u--&&r && r.nodeName !== "BODY") {
            if (t(r) && e(r.nodeName, i) && n(r, s, o)) return r;
            r = r.parentNode
        }
        return null
    }
    return function(e, t, n) {
        return n = n || 50,
        t.className || t.classRegExp ? i(e, t.nodeName, t.className, t.classRegExp, n) : r(e, t.nodeName, n)
    }
} (),
wysihtml5.dom.getStyle = function() {
    function n(e) {
        return e.replace(t, 
        function(e) {
            return e.charAt(1).toUpperCase()
        })
    }
    var e = {
        "float": "styleFloat" in document.createElement("div").style ? "styleFloat": "cssFloat"
    },
    t = /\-[a-z]/g;
    return function(t) {
        return {
            from: function(r) {
                if (r.nodeType !== wysihtml5.ELEMENT_NODE) return;
                var i = r.ownerDocument,
                s = e[t] || n(t),
                o = r.style,
                u = r.currentStyle,
                a = o[s];
                if (a) return a;
                if (u) try {
                    return u[s]
                } catch(f) {}
                var l = i.defaultView || i.parentWindow,
                c = (t === "height" || t === "width") && r.nodeName === "TEXTAREA",
                h,
                p;
                if (l.getComputedStyle) return c && (h = o.overflow, o.overflow = "hidden"),
                p = l.getComputedStyle(r, null).getPropertyValue(t),
                c && (o.overflow = h || ""),
                p
            }
        }
    }
} (),
wysihtml5.dom.hasElementWithTagName = function() {
    function n(e) {
        return e._wysihtml5_identifier || (e._wysihtml5_identifier = t++)
    }
    var e = {},
    t = 1;
    return function(t, r) {
        var i = n(t) + ":" + r,
        s = e[i];
        return s || (s = e[i] = t.getElementsByTagName(r)),
        s.length > 0
    }
} (),
function(e) {
    function r(e) {
        return e._wysihtml5_identifier || (e._wysihtml5_identifier = n++)
    }
    var t = {},
    n = 1;
    e.dom.hasElementWithClassName = function(n, i) {
        if (!e.browser.supportsNativeGetElementsByClassName()) return !! n.querySelector("." + i);
        var s = r(n) + ":" + i,
        o = t[s];
        return o || (o = t[s] = n.getElementsByClassName(i)),
        o.length > 0
    }
} (wysihtml5),
wysihtml5.dom.insert = function(e) {
    return {
        after: function(t) {
            t.parentNode.insertBefore(e, t.nextSibling)
        },
        before: function(t) {
            t.parentNode.insertBefore(e, t)
        },
        into: function(t) {
            t.appendChild(e)
        }
    }
},
wysihtml5.dom.insertCSS = function(e) {
    return e = e.join("\n"),
    {
        into: function(t) {
            var n = t.head || t.getElementsByTagName("head")[0],
            r = t.createElement("style");
            r.type = "text/css",
            r.styleSheet ? r.styleSheet.cssText = e: r.appendChild(t.createTextNode(e)),
            n && n.appendChild(r)
        }
    }
},
wysihtml5.dom.observe = function(e, t, n) {
    t = typeof t == "string" ? [t] : t;
    var r,
    i,
    s = 0,
    o = t.length;
    for (; s < o; s++) i = t[s],
    e.addEventListener ? e.addEventListener(i, n, !1) : (r = function(t) {
        "target" in t || (t.target = t.srcElement),
        t.preventDefault = t.preventDefault || 
        function() {
            this.returnValue = !1
        },
        t.stopPropagation = t.stopPropagation || 
        function() {
            this.cancelBubble = !0
        },
        n.call(e, t)
    },
    e.attachEvent("on" + i, r));
    return {
        stop: function() {
            var i,
            s = 0,
            o = t.length;
            for (; s < o; s++) i = t[s],
            e.removeEventListener ? e.removeEventListener(i, n, !1) : e.detachEvent("on" + i, r)
        }
    }
},
wysihtml5.dom.parse = function() {
    function s(e, t, n, s) {
        wysihtml5.lang.object(i).merge(r).merge(t).get(),
        n = n || e.ownerDocument || document;
        var u = n.createDocumentFragment(),
        a = typeof e == "string",
        f,
        l,
        c;
        a ? f = wysihtml5.dom.getAsDom(e, n) : f = e;
        while (f.firstChild) c = f.firstChild,
        f.removeChild(c),
        l = o(c, s),
        l && u.appendChild(l);
        return f.innerHTML = "",
        f.appendChild(u),
        a ? wysihtml5.quirks.getCorrectInnerHTML(f) : f
    }
    function o(n, r) {
        var i = n.nodeType,
        s = n.childNodes,
        u = s.length,
        a,
        f = e[i],
        l = 0;
        a = f && f(n);
        if (!a) return null;
        for (l = 0; l < u; l++) newChild = o(s[l], r),
        newChild && a.appendChild(newChild);
        return r && a.childNodes.length <= 1 && a.nodeName.toLowerCase() === t && !a.attributes.length ? a.firstChild: a
    }
    function u(e) {
        var n,
        r,
        s,
        o = i.tags,
        u = e.nodeName.toLowerCase(),
        f = e.scopeName;
        if (e._wysihtml5) return null;
        e._wysihtml5 = 1;
        if (e.className === "wysihtml5-temp") return null;
        f && f != "HTML" && (u = f + ":" + u),
        "outerHTML" in e && !wysihtml5.browser.autoClosesUnclosedTags() && e.nodeName === "P" && e.outerHTML.slice( - 4).toLowerCase() !== "</p>" && (u = "div");
        if (u in o) {
            n = o[u];
            if (!n || n.remove) return null;
            n = typeof n == "string" ? {
                rename_tag: n
            }: n
        } else {
            if (!e.firstChild) return null;
            n = {
                rename_tag: t
            }
        }
        return r = e.ownerDocument.createElement(n.rename_tag || u),
        a(e, r, n),
        e = null,
        r
    }
    function a(e, t, r) {
        var s = {},
        o = r.set_class,
        u = r.add_class,
        a = r.set_attributes,
        f = r.check_attributes,
        c = i.classes,
        h = 0,
        v = [],
        m = [],
        g = [],
        y = [],
        b,
        w,
        E,
        S,
        x,
        T,
        N;
        a && (s = wysihtml5.lang.object(a).clone());
        if (f) for (x in f) {
            N = p[f[x]];
            if (!N) continue;
            T = N(l(e, x)),
            typeof T == "string" && (s[x] = T)
        }
        o && v.push(o);
        if (u) for (x in u) {
            N = d[u[x]];
            if (!N) continue;
            S = N(l(e, x)),
            typeof S == "string" && v.push(S)
        }
        c["_wysihtml5-temp-placeholder"] = 1,
        y = e.getAttribute("class"),
        y && (v = v.concat(y.split(n))),
        b = v.length;
        for (; h < b; h++) E = v[h],
        c[E] && m.push(E);
        w = m.length;
        while (w--) E = m[w],
        wysihtml5.lang.array(g).contains(E) || g.unshift(E);
        g.length && (s["class"] = g.join(" "));
        for (x in s) try {
            t.setAttribute(x, s[x])
        } catch(C) {}
        s.src && (typeof s.width != "undefined" && t.setAttribute("width", s.width), typeof s.height != "undefined" && t.setAttribute("height", s.height))
    }
    function l(e, t) {
        t = t.toLowerCase();
        var n = e.nodeName;
        if (n == "IMG" && t == "src" && c(e) === !0) return e.src;
        if (f && "outerHTML" in e) {
            var r = e.outerHTML.toLowerCase(),
            i = r.indexOf(" " + t + "=") != -1;
            return i ? e.getAttribute(t) : null
        }
        return e.getAttribute(t)
    }
    function c(e) {
        try {
            return e.complete && !e.mozMatchesSelector(":-moz-broken")
        } catch(t) {
            if (e.complete && e.readyState === "complete") return ! 0
        }
    }
    function h(e) {
        return e.ownerDocument.createTextNode(e.data)
    }
    var e = {
        1: u,
        3: h
    },
    t = "span",
    n = /\s+/,
    r = {
        tags: {},
        classes: {}
    },
    i = {},
    f = !wysihtml5.browser.supportsGetAttributeCorrectly(),
    p = {
        url: function() {
            var e = /^https?:\/\//i;
            return function(t) {
                return ! t || !t.match(e) ? null: t.replace(e, 
                function(e) {
                    return e.toLowerCase()
                })
            }
        } (),
        alt: function() {
            var e = /[^ a-z0-9_\-]/gi;
            return function(t) {
                return t ? t.replace(e, "") : ""
            }
        } (),
        numbers: function() {
            var e = /\D/g;
            return function(t) {
                return t = (t || "").replace(e, ""),
                t || null
            }
        } (),
        href: function() {
            return function(e) {
                return e
            }
        } (),
        src: function() {
            return function(e) {
                return e
            }
        } ()
    },
    d = {
        align_img: function() {
            var e = {
                left: "wysiwyg-float-left",
                right: "wysiwyg-float-right"
            };
            return function(t) {
                return e[String(t).toLowerCase()]
            }
        } (),
        align_text: function() {
            var e = {
                left: "wysiwyg-text-align-left",
                right: "wysiwyg-text-align-right",
                center: "wysiwyg-text-align-center",
                justify: "wysiwyg-text-align-justify"
            };
            return function(t) {
                return e[String(t).toLowerCase()]
            }
        } (),
        clear_br: function() {
            var e = {
                left: "wysiwyg-clear-left",
                right: "wysiwyg-clear-right",
                both: "wysiwyg-clear-both",
                all: "wysiwyg-clear-both"
            };
            return function(t) {
                return e[String(t).toLowerCase()]
            }
        } (),
        size_font: function() {
            var e = {
                1: "wysiwyg-font-size-xx-small",
                2: "wysiwyg-font-size-small",
                3: "wysiwyg-font-size-medium",
                4: "wysiwyg-font-size-large",
                5: "wysiwyg-font-size-x-large",
                6: "wysiwyg-font-size-xx-large",
                7: "wysiwyg-font-size-xx-large",
                "-": "wysiwyg-font-size-smaller",
                "+": "wysiwyg-font-size-larger"
            };
            return function(t) {
                return e[String(t).charAt(0)]
            }
        } ()
    };
    return s
} (),
wysihtml5.dom.removeEmptyTextNodes = function(e) {
    var t,
    n = wysihtml5.lang.array(e.childNodes).get(),
    r = n.length,
    i = 0;
    for (; i < r; i++) t = n[i],
    t.nodeType === wysihtml5.TEXT_NODE && t.data === "" && t.parentNode.removeChild(t)
},
wysihtml5.dom.renameElement = function(e, t) {
    var n = e.ownerDocument.createElement(t),
    r;
    while (r = e.firstChild) n.appendChild(r);
    return wysihtml5.dom.copyAttributes(["align", "className"]).from(e).to(n),
    e.parentNode.replaceChild(n, e),
    n
},
wysihtml5.dom.replaceWithChildNodes = function(e) {
    if (!e.parentNode) return;
    if (!e.firstChild) {
        e.parentNode.removeChild(e);
        return
    }
    var t = e.ownerDocument.createDocumentFragment();
    while (e.firstChild) t.appendChild(e.firstChild);
    e.parentNode.replaceChild(t, e),
    e = t = null
},
function(e) {
    function t(t) {
        return e.getStyle("display").from(t) === "block"
    }
    function n(e) {
        return e.nodeName === "BR"
    }
    function r(e) {
        var t = e.ownerDocument.createElement("br");
        e.appendChild(t)
    }
    function i(e) {
        if (e.nodeName !== "MENU" && e.nodeName !== "UL" && e.nodeName !== "OL") return;
        var i = e.ownerDocument,
        s = i.createDocumentFragment(),
        o = e.previousElementSibling || e.previousSibling,
        u,
        a,
        f,
        l,
        c;
        o && !t(o) && r(s);
        while (c = e.firstChild) {
            a = c.lastChild;
            while (u = c.firstChild) f = u === a,
            l = f && !t(u) && !n(u),
            s.appendChild(u),
            l && r(s);
            c.parentNode.removeChild(c)
        }
        e.parentNode.replaceChild(s, e)
    }
    e.resolveList = i
} (wysihtml5.dom),
function(e) {
    var t = document,
    n = ["parent", "top", "opener", "frameElement", "frames", "localStorage", "globalStorage", "sessionStorage", "indexedDB"],
    r = ["open", "close", "openDialog", "showModalDialog", "alert", "confirm", "prompt", "openDatabase", "postMessage", "XMLHttpRequest", "XDomainRequest"],
    i = ["referrer", "write", "open", "close"];
    e.dom.Sandbox = Base.extend({
        constructor: function(t, n) {
            this.callback = t || e.EMPTY_FUNCTION,
            this.config = e.lang.object({}).merge(n).get(),
            this.iframe = this._createIframe()
        },
        insertInto: function(e) {
            typeof e == "string" && (e = t.getElementById(e)),
            e.appendChild(this.iframe)
        },
        getIframe: function() {
            return this.iframe
        },
        getWindow: function() {
            this._readyError()
        },
        getDocument: function() {
            this._readyError()
        },
        destroy: function() {
            var e = this.getIframe();
            e.parentNode.removeChild(e)
        },
        _readyError: function() {
            throw new Error("wysihtml5.Sandbox: Sandbox iframe isn't loaded yet")
        },
        _createIframe: function() {
            var n = this,
            r = t.createElement("iframe");
            return r.className = "wysihtml5-sandbox",
            e.dom.setAttributes({
                security: "restricted",
                allowtransparency: "true",
                frameborder: 0,
                width: 0,
                height: 0,
                marginwidth: 0,
                marginheight: 0
            }).on(r),
            e.browser.throwsMixedContentWarningWhenIframeSrcIsEmpty() && (r.src = "javascript:'<html></html>'"),
            r.onload = function() {
                r.onreadystatechange = r.onload = null,
                n._onLoadIframe(r)
            },
            r.onreadystatechange = function() { / loaded | complete / .test(r.readyState) && (r.onreadystatechange = r.onload = null, n._onLoadIframe(r))
            },
            r
        },
        _onLoadIframe: function(s) {
            if (!e.dom.contains(t.documentElement, s)) return;
            var o = this,
            u = s.contentWindow,
            a = s.contentWindow.document,
            f = t.characterSet || t.charset || "utf-8",
            l = this._getHtml({
                charset: f,
                stylesheets: this.config.stylesheets
            });
            a.open("text/html", "replace"),
            a.write(l),
            a.close(),
            this.getWindow = function() {
                return s.contentWindow
            },
            this.getDocument = function() {
                return s.contentWindow.document
            },
            u.onerror = function(e, t, n) {
                throw new Error("wysihtml5.Sandbox: " + e, t, n)
            };
            if (!e.browser.supportsSandboxedIframes()) {
                var c,
                h;
                for (c = 0, h = n.length; c < h; c++) this._unset(u, n[c]);
                for (c = 0, h = r.length; c < h; c++) this._unset(u, r[c], e.EMPTY_FUNCTION);
                for (c = 0, h = i.length; c < h; c++) this._unset(a, i[c]);
                this._unset(a, "cookie", "", !0)
            }
            this.loaded = !0,
            setTimeout(function() {
                o.callback(o)
            },
            0)
        },
        _getHtml: function(t) {
            var n = t.stylesheets,
            r = "",
            i = 0,
            s;
            n = typeof n == "string" ? [n] : n;
            if (n) {
                s = n.length;
                for (; i < s; i++) r += '<link rel="stylesheet" href="' + n[i] + '">'
            }
            return t.stylesheets = r,
            e.lang.string('<!DOCTYPE html><html><head><meta charset="#{charset}">#{stylesheets}</head><body style="display: none;"></body></html>').interpolate(t)
        },
        _unset: function(t, n, r, i) {
            try {
                t[n] = r
            } catch(s) {}
            try {
                t.__defineGetter__(n, 
                function() {
                    return r
                })
            } catch(s) {}
            if (i) try {
                t.__defineSetter__(n, 
                function() {})
            } catch(s) {}
            if (!e.browser.crashesWhenDefineProperty(n)) try {
                var o = {
                    get: function() {
                        return r
                    }
                };
                i && (o.set = function() {}),
                Object.defineProperty(t, n, o)
            } catch(s) {}
        }
    })
} (wysihtml5),
function() {
    var e = {
        className: "class"
    };
    wysihtml5.dom.setAttributes = function(t) {
        return {
            on: function(n) {
                for (var r in t) n.setAttribute(e[r] || r, t[r])
            }
        }
    }
} (),
wysihtml5.dom.setStyles = function(e) {
    return {
        on: function(t) {
            var n = t.style;
            if (typeof e == "string") {
                n.cssText += ";" + e;
                return
            }
            for (var r in e) r === "float" ? (n.cssFloat = e[r], n.styleFloat = e[r]) : n[r] = e[r]
        }
    }
},
function(e) {
    e.simulatePlaceholder = function(t, n, r) {
        var i = "placeholder",
        s = function() {
            n.hasPlaceholderSet() && n.clear(),
            e.removeClass(n.element, i)
        },
        o = function() {
            n.isEmpty() && (n.setValue(r), e.addClass(n.element, i))
        };
        t.observe("set_placeholder", o).observe("unset_placeholder", s).observe("focus:composer", s).observe("paste:composer", s).observe("blur:composer", o),
        o()
    }
} (wysihtml5.dom),
function(e) {
    var t = document.documentElement;
    "textContent" in t ? (e.setTextContent = function(e, t) {
        e.textContent = t
    },
    e.getTextContent = function(e) {
        return e.textContent
    }) : "innerText" in t ? (e.setTextContent = function(e, t) {
        e.innerText = t
    },
    e.getTextContent = function(e) {
        return e.innerText
    }) : (e.setTextContent = function(e, t) {
        e.nodeValue = t
    },
    e.getTextContent = function(e) {
        return e.nodeValue
    })
} (wysihtml5.dom),
wysihtml5.quirks.cleanPastedHTML = function() {
    function t(t, n, r) {
        n = n || e,
        r = r || t.ownerDocument || document;
        var i,
        s = typeof t == "string",
        o,
        u,
        a,
        f,
        l = 0;
        s ? i = wysihtml5.dom.getAsDom(t, r) : i = t;
        for (f in n) {
            u = i.querySelectorAll(f),
            o = n[f],
            a = u.length;
            for (; l < a; l++) o(u[l])
        }
        return u = t = n = null,
        s ? i.innerHTML: i
    }
    var e = {
        "a u": wysihtml5.dom.replaceWithChildNodes
    };
    return t
} (),
function(e) {
    var t = e.dom;
    e.quirks.ensureProperClearing = function() {
        var e = function(e) {
            var t = this;
            setTimeout(function() {
                var e = t.innerHTML.toLowerCase();
                if (e == "<p>&nbsp;</p>" || e == "<p>&nbsp;</p><p>&nbsp;</p>") t.innerHTML = ""
            },
            0)
        };
        return function(n) {
            t.observe(n.element, ["cut", "keydown"], e)
        }
    } (),
    e.quirks.ensureProperClearingOfLists = function() {
        var n = ["OL", "UL", "MENU"],
        r = function(r, i) {
            if (!i.firstChild || !e.lang.array(n).contains(i.firstChild.nodeName)) return;
            var s = t.getParentElement(r, {
                nodeName: n
            });
            if (!s) return;
            var o = s == i.firstChild;
            if (!o) return;
            var u = s.childNodes.length <= 1;
            if (!u) return;
            var a = s.firstChild ? s.firstChild.innerHTML === "": !0;
            if (!a) return;
            s.parentNode.removeChild(s)
        };
        return function(n) {
            t.observe(n.element, "keydown", 
            function(t) {
                if (t.keyCode !== e.BACKSPACE_KEY) return;
                var i = n.selection.getSelectedNode();
                r(i, n.element)
            })
        }
    } ()
} (wysihtml5),
function(e) {
    var t = "%7E";
    e.quirks.getCorrectInnerHTML = function(n) {
        var r = n.innerHTML;
        if (r.indexOf(t) === -1) return r;
        var i = n.querySelectorAll("[href*='~'], [src*='~']"),
        s,
        o,
        u,
        a;
        for (a = 0, u = i.length; a < u; a++) s = i[a].href || i[a].src,
        o = e.lang.string(s).replace("~").by(t),
        r = e.lang.string(r).replace(o).by(s);
        return r
    }
} (wysihtml5),
function(e) {
    var t = e.dom,
    n = ["LI", "P", "H1", "H2", "H3", "H4", "H5", "H6"],
    r = ["UL", "OL", "MENU"];
    e.quirks.insertLineBreakOnReturn = function(i) {
        function s(n) {
            var r = t.getParentElement(n, {
                nodeName: ["P", "DIV"]
            },
            2);
            if (!r) return;
            var s = document.createTextNode(e.INVISIBLE_SPACE);
            t.insert(s).before(r),
            t.replaceWithChildNodes(r),
            i.selection.selectNode(s)
        }
        function o(o) {
            var u = o.keyCode;
            if (o.shiftKey || u !== e.ENTER_KEY && u !== e.BACKSPACE_KEY) return;
            var a = o.target,
            f = i.selection.getSelectedNode(),
            l = t.getParentElement(f, {
                nodeName: n
            },
            4);
            if (l) {
                l.nodeName !== "LI" || u !== e.ENTER_KEY && u !== e.BACKSPACE_KEY ? l.nodeName.match(/H[1-6]/) && u === e.ENTER_KEY && setTimeout(function() {
                    s(i.selection.getSelectedNode())
                },
                0) : setTimeout(function() {
                    var e = i.selection.getSelectedNode(),
                    n,
                    o;
                    if (!e) return;
                    n = t.getParentElement(e, {
                        nodeName: r
                    },
                    2);
                    if (n) return;
                    s(e)
                },
                0);
                return
            }
            u === e.ENTER_KEY && !e.browser.insertsLineBreaksOnReturn() && (i.commands.exec("insertLineBreak"), o.preventDefault())
        }
        t.observe(i.element.ownerDocument, "keydown", o)
    }
} (wysihtml5),
function(e) {
    var t = "wysihtml5-quirks-redraw";
    e.quirks.redraw = function(n) {
        e.dom.addClass(n, t),
        e.dom.removeClass(n, t);
        try {
            var r = n.ownerDocument;
            r.execCommand("italic", !1, null),
            r.execCommand("italic", !1, null)
        } catch(i) {}
    }
} (wysihtml5),
function(e) {
    function n(e) {
        var t = 0;
        if (e.parentNode) do t += e.offsetTop || 0,
        e = e.offsetParent;
        while (e);
        return t
    }
    var t = e.dom;
    e.Selection = Base.extend({
        constructor: function(e) {
            window.rangy.init(),
            this.editor = e,
            this.composer = e.composer,
            this.doc = this.composer.doc
        },
        getBookmark: function() {
            var e = this.getRange();
            return e && e.cloneRange()
        },
        setBookmark: function(e) {
            if (!e) return;
            this.setSelection(e)
        },
        setBefore: function(e) {
            var t = rangy.createRange(this.doc);
            return t.setStartBefore(e),
            t.setEndBefore(e),
            this.setSelection(t)
        },
        setAfter: function(e) {
            var t = rangy.createRange(this.doc);
            return t.setStartAfter(e),
            t.setEndAfter(e),
            this.setSelection(t)
        },
        selectNode: function(n) {
            var r = rangy.createRange(this.doc),
            i = n.nodeType === e.ELEMENT_NODE,
            s = "canHaveHTML" in n ? n.canHaveHTML: n.nodeName !== "IMG",
            o = i ? n.innerHTML: n.data,
            u = o === "" || o === e.INVISIBLE_SPACE,
            a = t.getStyle("display").from(n),
            f = a === "block" || a === "list-item";
            if (u && i && s) try {
                n.innerHTML = e.INVISIBLE_SPACE
            } catch(l) {}
            s ? r.selectNodeContents(n) : r.selectNode(n),
            s && u && i ? r.collapse(f) : s && u && (r.setStartAfter(n), r.setEndAfter(n)),
            this.setSelection(r)
        },
        getSelectedNode: function(e) {
            var t,
            n;
            if (e && this.doc.selection && this.doc.selection.type === "Control") {
                n = this.doc.selection.createRange();
                if (n && n.length) return n.item(0)
            }
            return t = this.getSelection(this.doc),
            t.focusNode === t.anchorNode ? t.focusNode: (n = this.getRange(this.doc), n ? n.commonAncestorContainer: this.doc.body)
        },
        executeAndRestore: function(t, n) {
            var r = this.doc.body,
            i = n && r.scrollTop,
            s = n && r.scrollLeft,
            o = "_wysihtml5-temp-placeholder",
            u = '<span class="' + o + '">' + e.INVISIBLE_SPACE + "</span>",
            a = this.getRange(this.doc),
            f;
            if (!a) {
                t(r, r);
                return
            }
            var l = a.createContextualFragment(u);
            a.insertNode(l);
            try {
                t(a.startContainer, a.endContainer)
            } catch(c) {
                setTimeout(function() {
                    throw c
                },
                0)
            }
            caretPlaceholder = this.doc.querySelector("." + o),
            caretPlaceholder ? (f = rangy.createRange(this.doc), f.selectNode(caretPlaceholder), f.deleteContents(), this.setSelection(f)) : r.focus(),
            n && (r.scrollTop = i, r.scrollLeft = s);
            try {
                caretPlaceholder.parentNode.removeChild(caretPlaceholder)
            } catch(h) {}
        },
        executeAndRestoreSimple: function(e) {
            var t = this.getRange(),
            n = this.doc.body,
            r,
            i,
            s,
            o,
            u;
            if (!t) {
                e(n, n);
                return
            }
            o = t.getNodes([3]),
            i = o[0] || t.startContainer,
            s = o[o.length - 1] || t.endContainer,
            u = {
                collapsed: t.collapsed,
                startContainer: i,
                startOffset: i === t.startContainer ? t.startOffset: 0,
                endContainer: s,
                endOffset: s === t.endContainer ? t.endOffset: s.length
            };
            try {
                e(t.startContainer, t.endContainer)
            } catch(a) {
                setTimeout(function() {
                    throw a
                },
                0)
            }
            r = rangy.createRange(this.doc);
            try {
                r.setStart(u.startContainer, u.startOffset)
            } catch(f) {}
            try {
                r.setEnd(u.endContainer, u.endOffset)
            } catch(l) {}
            try {
                this.setSelection(r)
            } catch(c) {}
        },
        insertHTML: function(e) {
            var t = rangy.createRange(this.doc),
            n = t.createContextualFragment(e),
            r = n.lastChild;
            this.insertNode(n),
            r && this.setAfter(r)
        },
        insertNode: function(e) {
            var t = this.getRange();
            t && t.insertNode(e)
        },
        surround: function(e) {
            var t = this.getRange();
            if (!t) return;
            try {
                t.surroundContents(e),
                this.selectNode(e)
            } catch(n) {
                e.appendChild(t.extractContents()),
                t.insertNode(e)
            }
        },
        scrollIntoView: function() {
            var t = this.doc,
            r = t.documentElement.scrollHeight > t.documentElement.offsetHeight,
            i = t._wysihtml5ScrollIntoViewElement = t._wysihtml5ScrollIntoViewElement || 
            function() {
                var n = t.createElement("span");
                return n.innerHTML = e.INVISIBLE_SPACE,
                n
            } (),
            s;
            r && (this.insertNode(i), s = n(i), i.parentNode.removeChild(i), s > t.body.scrollTop && (t.body.scrollTop = s))
        },
        selectLine: function() {
            e.browser.supportsSelectionModify() ? this._selectLine_W3C() : this.doc.selection && this._selectLine_MSIE()
        },
        _selectLine_W3C: function() {
            var e = this.doc.defaultView,
            t = e.getSelection();
            t.modify("extend", "left", "lineboundary"),
            t.modify("extend", "right", "lineboundary")
        },
        _selectLine_MSIE: function() {
            var e = this.doc.selection.createRange(),
            t = e.boundingTop,
            n = e.boundingHeight,
            r = this.doc.body.scrollWidth,
            i,
            s,
            o,
            u,
            a;
            if (!e.moveToPoint) return;
            t === 0 && (o = this.doc.createElement("span"), this.insertNode(o), t = o.offsetTop, o.parentNode.removeChild(o)),
            t += 1;
            for (u = -10; u < r; u += 2) try {
                e.moveToPoint(u, t);
                break
            } catch(f) {}
            i = t,
            s = this.doc.selection.createRange();
            for (a = r; a >= 0; a--) try {
                s.moveToPoint(a, i);
                break
            } catch(l) {}
            e.setEndPoint("EndToEnd", s),
            e.select()
        },
        getText: function() {
            var e = this.getSelection();
            return e ? e.toString() : ""
        },
        getNodes: function(e, t) {
            var n = this.getRange();
            return n ? n.getNodes([e], t) : []
        },
        getRange: function() {
            var e = this.getSelection();
            return e && e.rangeCount && e.getRangeAt(0)
        },
        getSelection: function() {
            return rangy.getSelection(this.doc.defaultView || this.doc.parentWindow)
        },
        setSelection: function(e) {
            var t = this.doc.defaultView || this.doc.parentWindow,
            n = rangy.getSelection(t);
            return n.setSingleRange(e)
        }
    })
} (wysihtml5),
function(e, t) {
    function i(e, t, n) {
        if (!e.className) return ! 1;
        var r = e.className.match(n) || [];
        return r[r.length - 1] === t
    }
    function s(e, t, n) {
        e.className ? (o(e, n), e.className += " " + t) : e.className = t
    }
    function o(e, t) {
        e.className && (e.className = e.className.replace(t, ""))
    }
    function u(e, t) {
        return e.className.replace(r, " ") == t.className.replace(r, " ")
    }
    function a(e) {
        var t = e.parentNode;
        while (e.firstChild) t.insertBefore(e.firstChild, e);
        t.removeChild(e)
    }
    function f(e, t) {
        if (e.attributes.length != t.attributes.length) return ! 1;
        for (var n = 0, r = e.attributes.length, i, s, o; n < r; ++n) {
            i = e.attributes[n],
            o = i.name;
            if (o != "class") {
                s = t.attributes.getNamedItem(o);
                if (i.specified != s.specified) return ! 1;
                if (i.specified && i.nodeValue !== s.nodeValue) return ! 1
            }
        }
        return ! 0
    }
    function l(e, n) {
        return t.dom.isCharacterDataNode(e) ? n == 0 ? !!e.previousSibling: n == e.length ? !!e.nextSibling: !0: n > 0 && n < e.childNodes.length
    }
    function c(e, n, r) {
        var i;
        t.dom.isCharacterDataNode(n) && (r == 0 ? (r = t.dom.getNodeIndex(n), n = n.parentNode) : r == n.length ? (r = t.dom.getNodeIndex(n) + 1, n = n.parentNode) : i = t.dom.splitDataNode(n, r));
        if (!i) {
            i = n.cloneNode(!1),
            i.id && i.removeAttribute("id");
            var s;
            while (s = n.childNodes[r]) i.appendChild(s);
            t.dom.insertAfter(i, n)
        }
        return n == e ? i: c(e, i.parentNode, t.dom.getNodeIndex(i))
    }
    function h(t) {
        this.isElementMerge = t.nodeType == e.ELEMENT_NODE,
        this.firstTextNode = this.isElementMerge ? t.lastChild: t,
        this.textNodes = [this.firstTextNode]
    }
    function p(e, t, r, i) {
        this.tagNames = e || [n],
        this.cssClass = t || "",
        this.similarClassRegExp = r,
        this.normalize = i,
        this.applyToAnyTagName = !1
    }
    var n = "span",
    r = /\s+/g;
    h.prototype = {
        doMerge: function() {
            var e = [],
            t,
            n,
            r;
            for (var i = 0, s = this.textNodes.length; i < s; ++i) t = this.textNodes[i],
            n = t.parentNode,
            e[i] = t.data,
            i && (n.removeChild(t), n.hasChildNodes() || n.parentNode.removeChild(n));
            return this.firstTextNode.data = r = e.join(""),
            r
        },
        getLength: function() {
            var e = this.textNodes.length,
            t = 0;
            while (e--) t += this.textNodes[e].length;
            return t
        },
        toString: function() {
            var e = [];
            for (var t = 0, n = this.textNodes.length; t < n; ++t) e[t] = "'" + this.textNodes[t].data + "'";
            return "[Merge(" + e.join(",") + ")]"
        }
    },
    p.prototype = {
        getAncestorWithClass: function(n) {
            var r;
            while (n) {
                r = this.cssClass ? i(n, this.cssClass, this.similarClassRegExp) : !0;
                if (n.nodeType == e.ELEMENT_NODE && t.dom.arrayContains(this.tagNames, n.tagName.toLowerCase()) && r) return n;
                n = n.parentNode
            }
            return ! 1
        },
        postApply: function(e, t) {
            var n = e[0],
            r = e[e.length - 1],
            i = [],
            s,
            o = n,
            u = r,
            a = 0,
            f = r.length,
            l,
            c;
            for (var p = 0, d = e.length; p < d; ++p) l = e[p],
            c = this.getAdjacentMergeableTextNode(l.parentNode, !1),
            c ? (s || (s = new h(c), i.push(s)), s.textNodes.push(l), l === n && (o = s.firstTextNode, a = o.length), l === r && (u = s.firstTextNode, f = s.getLength())) : s = null;
            var v = this.getAdjacentMergeableTextNode(r.parentNode, !0);
            v && (s || (s = new h(r), i.push(s)), s.textNodes.push(v));
            if (i.length) {
                for (p = 0, d = i.length; p < d; ++p) i[p].doMerge();
                t.setStart(o, a),
                t.setEnd(u, f)
            }
        },
        getAdjacentMergeableTextNode: function(t, n) {
            var r = t.nodeType == e.TEXT_NODE,
            i = r ? t.parentNode: t,
            s,
            o = n ? "nextSibling": "previousSibling";
            if (r) {
                s = t[o];
                if (s && s.nodeType == e.TEXT_NODE) return s
            } else {
                s = i[o];
                if (s && this.areElementsMergeable(t, s)) return s[n ? "firstChild": "lastChild"]
            }
            return null
        },
        areElementsMergeable: function(e, n) {
            return t.dom.arrayContains(this.tagNames, (e.tagName || "").toLowerCase()) && t.dom.arrayContains(this.tagNames, (n.tagName || "").toLowerCase()) && u(e, n) && f(e, n)
        },
        createContainer: function(e) {
            var t = e.createElement(this.tagNames[0]);
            return this.cssClass && (t.className = this.cssClass),
            t
        },
        applyToTextNode: function(e) {
            var n = e.parentNode;
            if (n.childNodes.length == 1 && t.dom.arrayContains(this.tagNames, n.tagName.toLowerCase())) this.cssClass && s(n, this.cssClass, this.similarClassRegExp);
            else {
                var r = this.createContainer(t.dom.getDocument(e));
                e.parentNode.insertBefore(r, e),
                r.appendChild(e)
            }
        },
        isRemovable: function(n) {
            return t.dom.arrayContains(this.tagNames, n.tagName.toLowerCase()) && e.lang.string(n.className).trim() == this.cssClass
        },
        undoToTextNode: function(e, t, n) {
            if (!t.containsNode(n)) {
                var r = t.cloneRange();
                r.selectNode(n),
                r.isPointInRange(t.endContainer, t.endOffset) && l(t.endContainer, t.endOffset) && (c(n, t.endContainer, t.endOffset), t.setEndAfter(n)),
                r.isPointInRange(t.startContainer, t.startOffset) && l(t.startContainer, t.startOffset) && (n = c(n, t.startContainer, t.startOffset))
            }
            this.similarClassRegExp && o(n, this.similarClassRegExp),
            this.isRemovable(n) && a(n)
        },
        applyToRange: function(t) {
            var n = t.getNodes([e.TEXT_NODE]);
            if (!n.length) try {
                var r = this.createContainer(t.endContainer.ownerDocument);
                t.surroundContents(r),
                this.selectNode(t, r);
                return
            } catch(i) {}
            t.splitBoundaries(),
            n = t.getNodes([e.TEXT_NODE]);
            if (n.length) {
                var s;
                for (var o = 0, u = n.length; o < u; ++o) s = n[o],
                this.getAncestorWithClass(s) || this.applyToTextNode(s);
                t.setStart(n[0], 0),
                s = n[n.length - 1],
                t.setEnd(s, s.length),
                this.normalize && this.postApply(n, t)
            }
        },
        undoToRange: function(t) {
            var n = t.getNodes([e.TEXT_NODE]),
            r,
            i;
            if (n.length) t.splitBoundaries(),
            n = t.getNodes([e.TEXT_NODE]);
            else {
                var s = t.endContainer.ownerDocument,
                o = s.createTextNode(e.INVISIBLE_SPACE);
                t.insertNode(o),
                t.selectNode(o),
                n = [o]
            }
            for (var u = 0, a = n.length; u < a; ++u) r = n[u],
            i = this.getAncestorWithClass(r),
            i && this.undoToTextNode(r, t, i);
            a == 1 ? this.selectNode(t, n[0]) : (t.setStart(n[0], 0), r = n[n.length - 1], t.setEnd(r, r.length), this.normalize && this.postApply(n, t))
        },
        selectNode: function(t, n) {
            var r = n.nodeType === e.ELEMENT_NODE,
            i = "canHaveHTML" in n ? n.canHaveHTML: !0,
            s = r ? n.innerHTML: n.data,
            o = s === "" || s === e.INVISIBLE_SPACE;
            if (o && r && i) try {
                n.innerHTML = e.INVISIBLE_SPACE
            } catch(u) {}
            t.selectNodeContents(n),
            o && r ? t.collapse(!1) : o && (t.setStartAfter(n), t.setEndAfter(n))
        },
        getTextSelectedByRange: function(e, t) {
            var n = t.cloneRange();
            n.selectNodeContents(e);
            var r = n.intersection(t),
            i = r ? r.toString() : "";
            return n.detach(),
            i
        },
        isAppliedToRange: function(t) {
            var n = [],
            r,
            i = t.getNodes([e.TEXT_NODE]);
            if (!i.length) return r = this.getAncestorWithClass(t.startContainer),
            r ? [r] : !1;
            for (var s = 0, o = i.length, u; s < o; ++s) {
                u = this.getTextSelectedByRange(i[s], t),
                r = this.getAncestorWithClass(i[s]);
                if (u != "" && !r) return ! 1;
                n.push(r)
            }
            return n
        },
        toggleRange: function(e) {
            this.isAppliedToRange(e) ? this.undoToRange(e) : this.applyToRange(e)
        }
    },
    e.selection.HTMLApplier = p
} (wysihtml5, rangy),
wysihtml5.Commands = Base.extend({
    constructor: function(e) {
        this.editor = e,
        this.composer = e.composer,
        this.doc = this.composer.doc
    },
    support: function(e) {
        return wysihtml5.browser.supportsCommand(this.doc, e)
    },
    exec: function(e, t) {
        var n = wysihtml5.commands[e],
        r = wysihtml5.lang.array(arguments).get(),
        i = n && n.exec,
        s = null;
        this.editor.fire("beforecommand:composer");
        if (i) r.unshift(this.composer),
        s = i.apply(n, r);
        else try {
            s = this.doc.execCommand(e, !1, t)
        } catch(o) {}
        return this.editor.fire("aftercommand:composer"),
        s
    },
    state: function(e, t) {
        var n = wysihtml5.commands[e],
        r = wysihtml5.lang.array(arguments).get(),
        i = n && n.state;
        if (i) return r.unshift(this.composer),
        i.apply(n, r);
        try {
            return this.doc.queryCommandState(e)
        } catch(s) {
            return ! 1
        }
    },
    value: function(e) {
        var t = wysihtml5.commands[e],
        n = t && t.value;
        if (n) return n.call(t, this.composer, e);
        try {
            return this.doc.queryCommandValue(e)
        } catch(r) {
            return null
        }
    }
}),
function(e) {
    var t;
    e.commands.bold = {
        exec: function(t, n) {
            return e.commands.formatInline.exec(t, n, "b")
        },
        state: function(t, n, r) {
            return e.commands.formatInline.state(t, n, "b")
        },
        value: function() {
            return t
        }
    }
} (wysihtml5),
function(e) {
    function i(e, t) {
        var n = t.length,
        i = 0,
        s,
        o,
        u;
        for (; i < n; i++) s = t[i],
        o = r.getParentElement(s, {
            nodeName: "code"
        }),
        u = r.getTextContent(s),
        u.match(r.autoLink.URL_REG_EXP) && !o ? o = r.renameElement(s, "code") : r.replaceWithChildNodes(s)
    }
    function s(i, s) {
        var o = i.doc,
        u = "_wysihtml5-temp-" + +(new Date),
        a = /non-matching-class/g,
        f = 0,
        l,
        c,
        h,
        p,
        d,
        v,
        m,
        g,
        y;
        e.commands.formatInline.exec(i, t, n, u, a),
        c = o.querySelectorAll(n + "." + u),
        l = c.length;
        for (; f < l; f++) {
            h = c[f],
            h.removeAttribute("class");
            for (y in s) h.setAttribute(y, s[y])
        }
        v = h,
        l === 1 && (m = r.getTextContent(h), p = !!h.querySelector("*"), d = m === "" || m === e.INVISIBLE_SPACE, !p && d && (r.setTextContent(h, s.text || h.href), g = o.createTextNode(" "), i.selection.setAfter(h), i.selection.insertNode(g), v = g)),
        i.selection.setAfter(v)
    }
    var t,
    n = "A",
    r = e.dom;
    e.commands.createLink = {
        exec: function(e, t, n) {
            var r = this.state(e, t);
            r ? e.selection.executeAndRestore(function() {
                i(e, r)
            }) : (n = typeof n == "object" ? n: {
                href: n
            },
            s(e, n))
        },
        state: function(t, n) {
            return e.commands.formatInline.state(t, n, "A")
        },
        value: function() {
            return t
        }
    }
} (wysihtml5),
function(e) {
    var t,
    n = /wysiwyg-font-size-[a-z\-]+/g;
    e.commands.fontSize = {
        exec: function(t, r, i) {
            return e.commands.formatInline.exec(t, r, "span", "wysiwyg-font-size-" + i, n)
        },
        state: function(t, r, i) {
            return e.commands.formatInline.state(t, r, "span", "wysiwyg-font-size-" + i, n)
        },
        value: function() {
            return t
        }
    }
} (wysihtml5),
function(e) {
    var t,
    n = /wysiwyg-color-[a-z]+/g;
    e.commands.foreColor = {
        exec: function(t, r, i) {
            return e.commands.formatInline.exec(t, r, "span", "wysiwyg-color-" + i, n)
        },
        state: function(t, r, i) {
            return e.commands.formatInline.state(t, r, "span", "wysiwyg-color-" + i, n)
        },
        value: function() {
            return t
        }
    }
} (wysihtml5),
function(e) {
    function s(e, t, n) {
        e.className ? (o(e, n), e.className += " " + t) : e.className = t
    }
    function o(e, t) {
        e.className = e.className.replace(t, "")
    }
    function u(t) {
        return t.nodeType === e.TEXT_NODE && !e.lang.string(t.data).trim()
    }
    function a(e) {
        var t = e.previousSibling;
        while (t && u(t)) t = t.previousSibling;
        return t
    }
    function f(e) {
        var t = e.nextSibling;
        while (t && u(t)) t = t.nextSibling;
        return t
    }
    function l(e) {
        var t = e.ownerDocument,
        n = f(e),
        r = a(e);
        n && !d(n) && e.parentNode.insertBefore(t.createElement("br"), n),
        r && !d(r) && e.parentNode.insertBefore(t.createElement("br"), e)
    }
    function c(e) {
        var t = f(e),
        n = a(e);
        t && p(t) && t.parentNode.removeChild(t),
        n && p(n) && n.parentNode.removeChild(n)
    }
    function h(e) {
        var t = e.lastChild;
        t && p(t) && t.parentNode.removeChild(t)
    }
    function p(e) {
        return e.nodeName === "BR"
    }
    function d(e) {
        return p(e) ? !0: n.getStyle("display").from(e) === "block" ? !0: !1
    }
    function v(t, r, i, s) {
        if (s) var o = n.observe(t, "DOMNodeInserted", 
        function(t) {
            var r = t.target,
            i;
            if (r.nodeType !== e.ELEMENT_NODE) return;
            i = n.getStyle("display").from(r),
            i.substr(0, 6) !== "inline" && (r.className += " " + s)
        });
        t.execCommand(r, !1, i),
        o && o.stop()
    }
    function m(e, t) {
        e.selection.selectLine(),
        e.selection.surround(t),
        c(t),
        h(t),
        e.selection.selectNode(t)
    }
    function g(t) {
        return !! e.lang.string(t.className).trim()
    }
    var t,
    n = e.dom,
    r = "DIV",
    i = ["H1", "H2", "H3", "H4", "H5", "H6", "P", "BLOCKQUOTE", r];
    e.commands.formatBlock = {
        exec: function(t, u, a, f, c) {
            var h = t.doc,
            p = this.state(t, u, a, f, c),
            d;
            a = typeof a == "string" ? a.toUpperCase() : a;
            if (p) {
                t.selection.executeAndRestoreSimple(function() {
                    c && o(p, c);
                    var e = g(p); ! e && p.nodeName === (a || r) ? (l(p), n.replaceWithChildNodes(p)) : e && n.renameElement(p, r)
                });
                return
            }
            if (a === null || e.lang.array(i).contains(a)) {
                d = t.selection.getSelectedNode(),
                p = n.getParentElement(d, {
                    nodeName: i
                });
                if (p) {
                    t.selection.executeAndRestoreSimple(function() {
                        a && (p = n.renameElement(p, a)),
                        f && s(p, f, c)
                    });
                    return
                }
            }
            if (t.commands.support(u)) {
                v(h, u, a || r, f);
                return
            }
            p = h.createElement(a || r),
            f && (p.className = f),
            m(t, p)
        },
        state: function(e, t, r, i, s) {
            r = typeof r == "string" ? r.toUpperCase() : r;
            var o = e.selection.getSelectedNode();
            return n.getParentElement(o, {
                nodeName: r,
                className: i,
                classRegExp: s
            })
        },
        value: function() {
            return t
        }
    }
} (wysihtml5),
function(e) {
    function i(e) {
        var t = n[e];
        return t ? [e.toLowerCase(), t.toLowerCase()] : [e.toLowerCase()]
    }
    function s(t, n, s) {
        var o = t + ":" + n;
        return r[o] || (r[o] = new e.selection.HTMLApplier(i(t), n, s, !0)),
        r[o]
    }
    var t,
    n = {
        strong: "b",
        em: "i",
        b: "strong",
        i: "em"
    },
    r = {};
    e.commands.formatInline = {
        exec: function(e, t, n, r, i) {
            var o = e.selection.getRange();
            if (!o) return ! 1;
            s(n, r, i).toggleRange(o),
            e.selection.setSelection(o)
        },
        state: function(t, r, i, o, u) {
            var a = t.doc,
            f = n[i] || i,
            l;
            return ! e.dom.hasElementWithTagName(a, i) && !e.dom.hasElementWithTagName(a, f) ? !1: o && !e.dom.hasElementWithClassName(a, o) ? !1: (l = t.selection.getRange(), l ? s(i, o, u).isAppliedToRange(l) : !1)
        },
        value: function() {
            return t
        }
    }
} (wysihtml5),
function(e) {
    var t;
    e.commands.insertHTML = {
        exec: function(e, t, n) {
            e.commands.support(t) ? e.doc.execCommand(t, !1, n) : e.selection.insertHTML(n)
        },
        state: function() {
            return ! 1
        },
        value: function() {
            return t
        }
    }
} (wysihtml5),
function(e) {
    var t = "IMG";
    e.commands.insertImage = {
        exec: function(n, r, i) {
            i = typeof i == "object" ? i: {
                src: i
            };
            var s = n.doc,
            o = this.state(n),
            u,
            a,
            f;
            if (o) {
                n.selection.setBefore(o),
                f = o.parentNode,
                f.removeChild(o),
                e.dom.removeEmptyTextNodes(f),
                f.nodeName === "A" && !f.firstChild && (n.selection.setAfter(f), f.parentNode.removeChild(f)),
                e.quirks.redraw(n.element);
                return
            }
            o = s.createElement(t);
            for (a in i) o[a] = i[a];
            return n.selection.insertNode(o),
            e.browser.hasProblemsSettingCaretAfterImg() ? (u = s.createTextNode(e.INVISIBLE_SPACE), n.selection.insertNode(u), n.selection.setAfter(u)) : n.selection.setAfter(o),
            o
        },
        state: function(n) {
            var r = n.doc,
            i,
            s,
            o;
            return e.dom.hasElementWithTagName(r, t) ? (i = n.selection.getSelectedNode(), i ? i.nodeName === t ? i: i.nodeType !== e.ELEMENT_NODE ? !1: (s = n.selection.getText(), s = e.lang.string(s).trim(), s ? !1: (o = n.selection.getNodes(e.ELEMENT_NODE, 
            function(e) {
                return e.nodeName === "IMG"
            }), o.length !== 1 ? !1: o[0])) : !1) : !1
        },
        value: function(e) {
            var t = this.state(e);
            return t && t.src
        }
    }
} (wysihtml5),
function(e) {
    var t,
    n = "<br>" + (e.browser.needsSpaceAfterLineBreak() ? " ": "");
    e.commands.insertLineBreak = {
        exec: function(t, r) {
            t.commands.support(r) ? (t.doc.execCommand(r, !1, null), e.browser.autoScrollsToCaret() || t.selection.scrollIntoView()) : t.commands.exec("insertHTML", n)
        },
        state: function() {
            return ! 1
        },
        value: function() {
            return t
        }
    }
} (wysihtml5),
function(e) {
    var t;
    e.commands.insertOrderedList = {
        exec: function(t, n) {
            var r = t.doc,
            i = t.selection.getSelectedNode(),
            s = e.dom.getParentElement(i, {
                nodeName: "OL"
            }),
            o = e.dom.getParentElement(i, {
                nodeName: "UL"
            }),
            u = "_wysihtml5-temp-" + (new Date).getTime(),
            a,
            f;
            if (t.commands.support(n)) {
                r.execCommand(n, !1, null);
                return
            }
            s ? t.selection.executeAndRestoreSimple(function() {
                e.dom.resolveList(s)
            }) : o ? t.selection.executeAndRestoreSimple(function() {
                e.dom.renameElement(o, "ol")
            }) : (t.commands.exec("formatBlock", "div", u), f = r.querySelector("." + u), a = f.innerHTML === "" || f.innerHTML === e.INVISIBLE_SPACE, t.selection.executeAndRestoreSimple(function() {
                s = e.dom.convertToList(f, "ol")
            }), a && 
            t.selection.selectNode(s.querySelector("li")))
        },
        state: function(t) {
            var n = t.selection.getSelectedNode();
            return e.dom.getParentElement(n, {
                nodeName: "OL"
            })
        },
        value: function() {
            return t
        }
    }
} (wysihtml5),
function(e) {
    var t;
    e.commands.insertUnorderedList = {
        exec: function(t, n) {
            var r = t.doc,
            i = t.selection.getSelectedNode(),
            s = e.dom.getParentElement(i, {
                nodeName: "UL"
            }),
            o = e.dom.getParentElement(i, {
                nodeName: "OL"
            }),
            u = "_wysihtml5-temp-" + (new Date).getTime(),
            a,
            f;
            if (t.commands.support(n)) {
                r.execCommand(n, !1, null);
                return
            }
            s ? t.selection.executeAndRestoreSimple(function() {
                e.dom.resolveList(s)
            }) : o ? t.selection.executeAndRestoreSimple(function() {
                e.dom.renameElement(o, "ul")
            }) : (t.commands.exec("formatBlock", "div", u), f = r.querySelector("." + u), a = f.innerHTML === "" || f.innerHTML === e.INVISIBLE_SPACE, t.selection.executeAndRestoreSimple(function() {
                s = e.dom.convertToList(f, "ul")
            }), a && t.selection.selectNode(s.querySelector("li")))
        },
        state: function(t) {
            var n = t.selection.getSelectedNode();
            return e.dom.getParentElement(n, {
                nodeName: "UL"
            })
        },
        value: function() {
            return t
        }
    }
} (wysihtml5),
function(e) {
    var t;
    e.commands.italic = {
        exec: function(t, n) {
            return e.commands.formatInline.exec(t, n, "i")
        },
        state: function(t, n, r) {
            return e.commands.formatInline.state(t, n, "i")
        },
        value: function() {
            return t
        }
    }
} (wysihtml5),
function(e) {
    var t,
    n = "wysiwyg-text-align-center",
    r = /wysiwyg-text-align-[a-z]+/g;
    e.commands.justifyCenter = {
        exec: function(t, i) {
            return e.commands.formatBlock.exec(t, "formatBlock", null, n, r)
        },
        state: function(t, i) {
            return e.commands.formatBlock.state(t, "formatBlock", null, n, r)
        },
        value: function() {
            return t
        }
    }
} (wysihtml5),
function(e) {
    var t,
    n = "wysiwyg-text-align-left",
    r = /wysiwyg-text-align-[a-z]+/g;
    e.commands.justifyLeft = {
        exec: function(t, i) {
            return e.commands.formatBlock.exec(t, "formatBlock", null, n, r)
        },
        state: function(t, i) {
            return e.commands.formatBlock.state(t, "formatBlock", null, n, r)
        },
        value: function() {
            return t
        }
    }
} (wysihtml5),
function(e) {
    var t,
    n = "wysiwyg-text-align-right",
    r = /wysiwyg-text-align-[a-z]+/g;
    e.commands.justifyRight = {
        exec: function(t, i) {
            return e.commands.formatBlock.exec(t, "formatBlock", null, n, r)
        },
        state: function(t, i) {
            return e.commands.formatBlock.state(t, "formatBlock", null, n, r)
        },
        value: function() {
            return t
        }
    }
} (wysihtml5),
function(e) {
    var t;
    e.commands.underline = {
        exec: function(t, n) {
            return e.commands.formatInline.exec(t, n, "u")
        },
        state: function(t, n) {
            return e.commands.formatInline.state(t, n, "u")
        },
        value: function() {
            return t
        }
    }
} (wysihtml5),
function(e) {
    function f(e) {
        var t;
        while (t = e.querySelector("._wysihtml5-temp")) t.parentNode.removeChild(t)
    }
    var t = 90,
    n = 89,
    r = 8,
    i = 46,
    s = 40,
    o = '<span id="_wysihtml5-undo" class="_wysihtml5-temp">' + e.INVISIBLE_SPACE + "</span>",
    u = '<span id="_wysihtml5-redo" class="_wysihtml5-temp">' + e.INVISIBLE_SPACE + "</span>",
    a = e.dom;
    e.UndoManager = e.lang.Dispatcher.extend({
        constructor: function(e) {
            this.editor = e,
            this.composer = e.composer,
            this.element = this.composer.element,
            this.history = [this.composer.getValue()],
            this.position = 1,
            this.composer.commands.support("insertHTML") && this._observe()
        },
        _observe: function() {
            var s = this,
            l = this.composer.sandbox.getDocument(),
            c;
            a.observe(this.element, "keydown", 
            function(e) {
                var r = /Mac/.test(navigator.userAgent),
                i = r ? e.metaKey: e.ctrlKey;
                if (e.altKey || !i) return;
                var o = e.keyCode,
                u = o === t && !e.shiftKey,
                a = o === t && e.shiftKey || o === n;
                u ? (s.undo(), e.preventDefault()) : a && (s.redo(), e.preventDefault())
            }),
            a.observe(this.element, "keydown", 
            function(e) {
                var t = e.keyCode;
                if (t === c) return;
                c = t,
                (t === r || t === i) && s.transact()
            });
            if (e.browser.hasUndoInContextMenu()) {
                var h,
                p,
                d = function() {
                    f(l),
                    clearInterval(h)
                };
                a.observe(this.element, "contextmenu", 
                function() {
                    d(),
                    s.composer.selection.executeAndRestoreSimple(function() {
                        s.element.lastChild && s.composer.selection.setAfter(s.element.lastChild),
                        l.execCommand("insertHTML", !1, o),
                        l.execCommand("insertHTML", !1, u),
                        l.execCommand("undo", !1, null)
                    }),
                    h = setInterval(function() {
                        l.getElementById("_wysihtml5-redo") ? (d(), s.redo()) : l.getElementById("_wysihtml5-undo") || (d(), s.undo())
                    },
                    400),
                    p || (p = !0, a.observe(document, "mousedown", d), a.observe(l, ["mousedown", "paste", "cut", "copy"], d))
                })
            }
            this.editor.observe("newword:composer", 
            function() {
                s.transact()
            }).observe("beforecommand:composer", 
            function() {
                s.transact()
            })
        },
        transact: function() {
            var e = this.history[this.position - 1],
            t = this.composer.getValue();
            if (t == e) return;
            var n = this.history.length = this.position;
            n > s && (this.history.shift(), this.position--),
            this.position++,
            this.history.push(t)
        },
        undo: function() {
            this.transact();
            if (this.position <= 1) return;
            this.set(this.history[--this.position - 1]),
            this.editor.fire("undo:composer")
        },
        redo: function() {
            if (this.position >= this.history.length) return;
            this.set(this.history[++this.position - 1]),
            this.editor.fire("redo:composer")
        },
        set: function(e) {
            this.composer.setValue(e),
            this.editor.focus(!0)
        }
    })
} (wysihtml5),
wysihtml5.views.View = Base.extend({
    constructor: function(e, t, n) {
        this.parent = e,
        this.element = t,
        this.config = n,
        this._observeViewChange()
    },
    _observeViewChange: function() {
        var e = this;
        this.parent.observe("beforeload", 
        function() {
            e.parent.observe("change_view", 
            function(t) {
                t === e.name ? (e.parent.currentView = e, e.show(), setTimeout(function() {
                    e.focus()
                },
                0)) : e.hide()
            })
        })
    },
    focus: function() {
        if (this.element.ownerDocument.querySelector(":focus") === this.element) return;
        try {
            this.element.focus()
        } catch(e) {}
    },
    hide: function() {
        this.element.style.display = "none"
    },
    show: function() {
        this.element.style.display = ""
    },
    disable: function() {
        this.element.setAttribute("disabled", "disabled")
    },
    enable: function() {
        this.element.removeAttribute("disabled")
    }
}),
function(e) {
    var t = e.dom,
    n = e.browser;
    e.views.Composer = e.views.View.extend({
        name: "composer",
        CARET_HACK: "<br>",
        constructor: function(e, t, n) {
            this.base(e, t, n),
            this.textarea = this.parent.textarea,
            this._initSandbox()
        },
        clear: function() {
            this.element.innerHTML = n.displaysCaretInEmptyContentEditableCorrectly() ? "": this.CARET_HACK
        },
        getValue: function(t) {
            var n = this.isEmpty() ? "": e.quirks.getCorrectInnerHTML(this.element);
            return t && (n = this.parent.parse(n)),
            n = e.lang.string(n).replace(e.INVISIBLE_SPACE).by(""),
            n
        },
        setValue: function(e, t) {
            t && (e = this.parent.parse(e)),
            this.element.innerHTML = e
        },
        show: function() {
            this.iframe.style.display = this._displayStyle || "",
            this.disable(),
            this.enable()
        },
        hide: function() {
            this._displayStyle = t.getStyle("display").from(this.iframe),
            this._displayStyle === "none" && (this._displayStyle = null),
            this.iframe.style.display = "none"
        },
        disable: function() {
            this.element.removeAttribute("contentEditable"),
            this.base()
        },
        enable: function() {
            this.element.setAttribute("contentEditable", "true"),
            this.base()
        },
        focus: function(t) {
            e.browser.doesAsyncFocus() && this.hasPlaceholderSet() && this.clear(),
            this.base();
            var n = this.element.lastChild;
            t && n && (n.nodeName === "BR" ? this.selection.setBefore(this.element.lastChild) : this.selection.setAfter(this.element.lastChild))
        },
        getTextContent: function() {
            return t.getTextContent(this.element)
        },
        hasPlaceholderSet: function() {
            return this.getTextContent() == this.textarea.element.getAttribute("placeholder")
        },
        isEmpty: function() {
            var e = this.element.innerHTML,
            t = "blockquote, ul, ol, img, embed, object, table, iframe, svg, video, audio, button, input, select, textarea";
            return e === "" || e === this.CARET_HACK || this.hasPlaceholderSet() || this.getTextContent() === "" && !this.element.querySelector(t)
        },
        _initSandbox: function() {
            var e = this;
            this.sandbox = new t.Sandbox(function() {
                e._create()
            },
            {
                stylesheets: this.config.stylesheets
            }),
            this.iframe = this.sandbox.getIframe();
            var n = document.createElement("input");
            n.type = "hidden",
            n.name = "_wysihtml5_mode",
            n.value = 1;
            var r = this.textarea.element;
            t.insert(this.iframe).after(r),
            t.insert(n).after(r)
        },
        _create: function() {
            var r = this;
            this.doc = this.sandbox.getDocument(),
            this.element = this.doc.body,
            this.textarea = this.parent.textarea,
            this.element.innerHTML = this.textarea.getValue(!0),
            this.enable(),
            this.selection = new e.Selection(this.parent),
            this.commands = new e.Commands(this.parent),
            t.copyAttributes(["className", "spellcheck", "title", "lang", "dir", "accessKey"]).from(this.textarea.element).to(this.element),
            t.addClass(this.element, this.config.composerClassName),
            this.config.style && this.style(),
            this.observe();
            var i = this.config.name;
            i && (t.addClass(this.element, i), t.addClass(this.iframe, i));
            var s = typeof this.config.placeholder == "string" ? this.config.placeholder: this.textarea.element.getAttribute("placeholder");
            s && t.simulatePlaceholder(this.parent, this, s),
            this.commands.exec("styleWithCSS", !1),
            this._initAutoLinking(),
            this._initObjectResizing(),
            this._initUndoManager(),
            (this.textarea.element.hasAttribute("autofocus") || document.querySelector(":focus") == this.textarea.element) && setTimeout(function() {
                r.focus()
            },
            100),
            e.quirks.insertLineBreakOnReturn(this),
            n.clearsContentEditableCorrectly() || e.quirks.ensureProperClearing(this),
            n.clearsListsInContentEditableCorrectly() || e.quirks.ensureProperClearingOfLists(this),
            this.initSync && this.config.sync && this.initSync(),
            this.textarea.hide(),
            this.parent.fire("beforeload").fire("load")
        },
        _initAutoLinking: function() {
            var r = this,
            i = n.canDisableAutoLinking(),
            s = n.doesAutoLinkingInContentEditable();
            i && this.commands.exec("autoUrlDetect", !1);
            if (!this.config.autoLink) return; (!s || s && i) && this.parent.observe("newword:composer", 
            function() {
                r.selection.executeAndRestore(function(e, n) {
                    t.autoLink(n.parentNode)
                })
            });
            var o = this.sandbox.getDocument().getElementsByTagName("a"),
            u = t.autoLink.URL_REG_EXP,
            a = function(n) {
                var r = e.lang.string(t.getTextContent(n)).trim();
                return r.substr(0, 4) === "www." && (r = "http://" + r),
                r
            };
            t.observe(this.element, "keydown", 
            function(e) {
                if (!o.length) return;
                var n = r.selection.getSelectedNode(e.target.ownerDocument),
                i = t.getParentElement(n, {
                    nodeName: "A"
                },
                4),
                s;
                if (!i) return;
                s = a(i),
                setTimeout(function() {
                    var e = a(i);
                    if (e === s) return;
                    e.match(u) && i.setAttribute("href", e)
                },
                0)
            })
        },
        _initObjectResizing: function() {
            var r = ["width", "height"],
            i = r.length,
            s = this.element;
            this.commands.exec("enableObjectResizing", this.config.allowObjectResizing),
            this.config.allowObjectResizing ? n.supportsEvent("resizeend") && t.observe(s, "resizeend", 
            function(t) {
                var n = t.target || t.srcElement,
                o = n.style,
                u = 0,
                a;
                for (; u < i; u++) a = r[u],
                o[a] && (n.setAttribute(a, parseInt(o[a], 10)), o[a] = "");
                e.quirks.redraw(s)
            }) : n.supportsEvent("resizestart") && t.observe(s, "resizestart", 
            function(e) {
                e.preventDefault()
            })
        },
        _initUndoManager: function() {
            new e.UndoManager(this.parent)
        }
    })
} (wysihtml5),
function(e) {
    var t = e.dom,
    n = document,
    r = window,
    i = n.createElement("div"),
    s = ["background-color", "color", "cursor", "font-family", "font-size", "font-style", "font-variant", "font-weight", "line-height", "letter-spacing", "text-align", "text-decoration", "text-indent", "text-rendering", "word-break", "word-wrap", "word-spacing"],
    o = ["background-color", "border-collapse", "border-bottom-color", "border-bottom-style", "border-bottom-width", "border-left-color", "border-left-style", "border-left-width", "border-right-color", "border-right-style", "border-right-width", "border-top-color", "border-top-style", "border-top-width", "clear", "display", "float", "margin-bottom", "margin-left", "margin-right", "margin-top", "outline-color", "outline-offset", "outline-width", "outline-style", "padding-left", "padding-right", "padding-top", "padding-bottom", "position", "top", "left", "right", "bottom", "z-index", "vertical-align", "text-align", "-webkit-box-sizing", "-moz-box-sizing", "-ms-box-sizing", "box-sizing", "-webkit-box-shadow", "-moz-box-shadow", "-ms-box-shadow", "box-shadow", "-webkit-border-top-right-radius", "-moz-border-radius-topright", "border-top-right-radius", "-webkit-border-bottom-right-radius", "-moz-border-radius-bottomright", "border-bottom-right-radius", "-webkit-border-bottom-left-radius", "-moz-border-radius-bottomleft", "border-bottom-left-radius", "-webkit-border-top-left-radius", "-moz-border-radius-topleft", "border-top-left-radius", "width", "height"],
    u = ["width", "height", "top", "left", "right", "bottom"],
    a = ["html             { height: 100%; }", "body             { min-height: 100%; padding: 0; margin: 0; margin-top: -1px; padding-top: 1px; }", "._wysihtml5-temp { display: none; }", e.browser.isGecko ? "body.placeholder { color: graytext !important; }": "body.placeholder { color: #a9a9a9 !important; }", "body[disabled]   { background-color: #eee !important; color: #999 !important; cursor: default !important; }", "img:-moz-broken  { -moz-force-broken-image-icon: 1; height: 24px; width: 24px; }"],
    f = function(e) {
        if (e.setActive) try {
            e.setActive()
        } catch(i) {} else {
            var s = e.style,
            o = n.documentElement.scrollTop || n.body.scrollTop,
            u = n.documentElement.scrollLeft || n.body.scrollLeft,
            a = {
                position: s.position,
                top: s.top,
                left: s.left,
                WebkitUserSelect: s.WebkitUserSelect
            };
            t.setStyles({
                position: "absolute",
                top: "-99999px",
                left: "-99999px",
                WebkitUserSelect: "none"
            }).on(e),
            e.focus(),
            t.setStyles(a).on(e),
            r.scrollTo && r.scrollTo(u, o)
        }
    };
    e.views.Composer.prototype.style = function() {
        var l = this,
        c = n.querySelector(":focus"),
        h = this.textarea.element,
        p = h.hasAttribute("placeholder"),
        d = p && h.getAttribute("placeholder");
        this.focusStylesHost = this.focusStylesHost || i.cloneNode(!1),
        this.blurStylesHost = this.blurStylesHost || i.cloneNode(!1),
        p && h.removeAttribute("placeholder"),
        h === c && h.blur(),
        t.copyStyles(o).from(h).to(this.iframe).andTo(this.blurStylesHost),
        t.copyStyles(s).from(h).to(this.element).andTo(this.blurStylesHost),
        t.insertCSS(a).into(this.element.ownerDocument),
        f(h),
        t.copyStyles(o).from(h).to(this.focusStylesHost),
        t.copyStyles(s).from(h).to(this.focusStylesHost);
        var v = e.lang.array(o).without(["display"]);
        c ? c.focus() : h.blur(),
        p && h.setAttribute("placeholder", d);
        if (!e.browser.hasCurrentStyleProperty()) var m = t.observe(r, "resize", 
        function() {
            if (!t.contains(document.documentElement, l.iframe)) {
                m.stop();
                return
            }
            var e = t.getStyle("display").from(h),
            n = t.getStyle("display").from(l.iframe);
            h.style.display = "",
            l.iframe.style.display = "none",
            t.copyStyles(u).from(h).to(l.iframe).andTo(l.focusStylesHost).andTo(l.blurStylesHost),
            l.iframe.style.display = n,
            h.style.display = e
        });
        return this.parent.observe("focus:composer", 
        function() {
            t.copyStyles(v).from(l.focusStylesHost).to(l.iframe),
            t.copyStyles(s).from(l.focusStylesHost).to(l.element)
        }),
        this.parent.observe("blur:composer", 
        function() {
            t.copyStyles(v).from(l.blurStylesHost).to(l.iframe),
            t.copyStyles(s).from(l.blurStylesHost).to(l.element)
        }),
        this
    }
} (wysihtml5),
function(e) {
    var t = e.dom,
    n = e.browser,
    r = {
        66: "bold",
        73: "italic",
        85: "underline"
    };
    e.views.Composer.prototype.observe = function() {
        var i = this,
        s = this.getValue(),
        o = this.sandbox.getIframe(),
        u = this.element,
        a = n.supportsEventsInIframeCorrectly() ? u: this.sandbox.getWindow(),
        f = n.supportsEvent("drop") ? ["drop", "paste"] : ["dragdrop", "paste"];
        t.observe(o, "DOMNodeRemoved", 
        function() {
            clearInterval(l),
            i.parent.fire("destroy:composer")
        });
        var l = setInterval(function() {
            t.contains(document.documentElement, o) || (clearInterval(l), i.parent.fire("destroy:composer"))
        },
        250);
        t.observe(a, "focus", 
        function() {
            i.parent.fire("focus").fire("focus:composer"),
            setTimeout(function() {
                s = i.getValue()
            },
            0)
        }),
        t.observe(a, "blur", 
        function() {
            s !== i.getValue() && i.parent.fire("change").fire("change:composer"),
            i.parent.fire("blur").fire("blur:composer")
        }),
        e.browser.isIos() && t.observe(u, "blur", 
        function() {
            var e = u.ownerDocument.createElement("input"),
            t = document.documentElement.scrollTop || document.body.scrollTop,
            n = document.documentElement.scrollLeft || document.body.scrollLeft;
            try {
                i.selection.insertNode(e)
            } catch(r) {
                u.appendChild(e)
            }
            e.focus(),
            e.parentNode.removeChild(e),
            window.scrollTo(n, t)
        }),
        t.observe(u, "dragenter", 
        function(e) {
            i.parent.fire("unset_placeholder")
        }),
        n.firesOnDropOnlyWhenOnDragOverIsCancelled() && t.observe(u, ["dragover", "dragenter"], 
        function(e) {
            e.preventDefault()
        }),
        t.observe(u, f, 
        function(e) {
            var t = e.dataTransfer || e.clipboardData;
            t && n.supportsDataTransfer() ? (u.focus(), i.parent.fire("paste").fire("paste:composer", {
                dataTransfer: t,
                originalEvent: e
            })) : setTimeout(function() {
                i.parent.fire("paste").fire("paste:composer")
            },
            0)
        }),
        t.observe(u, "keyup", 
        function(t) {
            var n = t.keyCode; (n === e.SPACE_KEY || n === e.ENTER_KEY) && i.parent.fire("newword:composer")
        }),
        this.parent.observe("paste:composer", 
        function() {
            setTimeout(function() {
                i.parent.fire("newword:composer")
            },
            0)
        }),
        n.canSelectImagesInContentEditable() || t.observe(u, "mousedown", 
        function(e) {
            var t = e.target;
            t.nodeName === "IMG" && (i.selection.selectNode(t), e.preventDefault())
        }),
        t.observe(u, "keydown", 
        function(e) {
            var t = e.keyCode,
            n = r[t],
            s = /Mac/.test(navigator.userAgent),
            o = s ? e.metaKey: e.ctrlKey;
            o && !e.altKey && n && (i.commands.exec(n), e.preventDefault())
        }),
        t.observe(u, "keydown", 
        function(t) {
            var n = i.selection.getSelectedNode(!0),
            r = t.keyCode,
            s;
            n && n.nodeName === "IMG" && (r === e.BACKSPACE_KEY || r === e.DELETE_KEY) && (s = n.parentNode, s.removeChild(n), s.nodeName === "A" && !s.firstChild && s.parentNode.removeChild(s), setTimeout(function() {
                e.quirks.redraw(u)
            },
            0), t.preventDefault())
        })
    }
} (wysihtml5),
function(e) {
    var t = 400;
    e.views.Synchronizer = Base.extend({
        constructor: function(e, t, n) {
            this.editor = e,
            this.textarea = t,
            this.composer = n,
            this._observe()
        },
        fromComposerToTextarea: function(t) {
            this.textarea.setValue(e.lang.string(this.composer.getValue()).trim(), t)
        },
        fromTextareaToComposer: function(e) {
            var t = this.textarea.getValue();
            t ? this.composer.setValue(t, e) : (this.composer.clear(), this.editor.fire("set_placeholder"))
        },
        sync: function(e) {
            this.editor.currentView.name === "textarea" ? this.fromTextareaToComposer(e) : this.fromComposerToTextarea(e)
        },
        _observe: function() {
            var n,
            r = this,
            i = this.textarea.element.form,
            s = function() {
                n = setInterval(function() {
                    r.fromComposerToTextarea()
                },
                t)
            },
            o = function() {
                clearInterval(n),
                n = null
            };
            s(),
            i && ($(i).data("submitEvent", e.dom.observe(i, "submit", 
            function() {
                r.sync(!0)
            })), $(i).data("resetEvent", e.dom.observe(i, "reset", 
            function() {
                setTimeout(function() {
                    r.fromTextareaToComposer()
                },
                0)
            }))),
            this.editor.observe("change_view", 
            function(e) {
                e === "composer" && !n ? (r.fromTextareaToComposer(!0), s()) : e === "textarea" && (r.fromComposerToTextarea(!0), o())
            }),
            this.editor.observe("destroy:composer", o)
        }
    })
} (wysihtml5),
wysihtml5.views.Textarea = wysihtml5.views.View.extend({
    name: "textarea",
    constructor: function(e, t, n) {
        this.base(e, t, n),
        this._observe()
    },
    clear: function() {
        this.element.value = ""
    },
    getValue: function(e) {
        var t = this.isEmpty() ? "": this.element.value;
        return e && (t = this.parent.parse(t)),
        t
    },
    setValue: function(e, t) {
        t && (e = this.parent.parse(e)),
        this.element.value = e
    },
    hasPlaceholderSet: function() {
        var e = wysihtml5.browser.supportsPlaceholderAttributeOn(this.element),
        t = this.element.getAttribute("placeholder") || null,
        n = this.element.value,
        r = !n;
        return e && r || n === t
    },
    isEmpty: function() {
        return ! wysihtml5.lang.string(this.element.value).trim() || this.hasPlaceholderSet()
    },
    _observe: function() {
        var e = this.element,
        t = this.parent,
        n = {
            focusin: "focus",
            focusout: "blur"
        },
        r = wysihtml5.browser.supportsEvent("focusin") ? ["focusin", "focusout", "change"] : ["focus", "blur", "change"];
        t.observe("beforeload", 
        function() {
            wysihtml5.dom.observe(e, r, 
            function(e) {
                var r = n[e.type] || e.type;
                t.fire(r).fire(r + ":textarea")
            }),
            wysihtml5.dom.observe(e, ["paste", "drop"], 
            function() {
                setTimeout(function() {
                    t.fire("paste").fire("paste:textarea")
                },
                0)
            })
        })
    }
}),
function(e) {
    var t = e.dom,
    n = "wysihtml5-command-dialog-opened",
    r = "input, select, textarea",
    i = "[data-wysihtml5-dialog-field]",
    s = "data-wysihtml5-dialog-field";
    e.toolbar.Dialog = e.lang.Dispatcher.extend({
        constructor: function(e, t) {
            this.link = e,
            this.container = t
        },
        _observe: function() {
            if (this._observed) return;
            var i = this,
            s = function(e) {
                var t = i._serialize();
                t == i.elementToChange ? i.fire("edit", t) : i.fire("save", t),
                i.hide(),
                e.preventDefault(),
                e.stopPropagation()
            };
            t.observe(i.link, "click", 
            function(e) {
                t.hasClass(i.link, n) && setTimeout(function() {
                    i.hide()
                },
                0)
            }),
            t.observe(this.container, "keydown", 
            function(t) {
                var n = t.keyCode;
                n === e.ENTER_KEY && s(t),
                n === e.ESCAPE_KEY && i.hide()
            }),
            t.delegate(this.container, "[data-wysihtml5-dialog-action=save]", "click", s),
            t.delegate(this.container, "[data-wysihtml5-dialog-action=cancel]", "click", 
            function(e) {
                i.fire("cancel"),
                i.hide(),
                e.preventDefault(),
                e.stopPropagation()
            });
            var o = this.container.querySelectorAll(r),
            u = 0,
            a = o.length,
            f = function() {
                clearInterval(i.interval)
            };
            for (; u < a; u++) t.observe(o[u], "change", f);
            this._observed = !0
        },
        _serialize: function() {
            var e = this.elementToChange || {},
            t = this.container.querySelectorAll(i),
            n = t.length,
            r = 0;
            for (; r < n; r++) e[t[r].getAttribute(s)] = t[r].value;
            return e
        },
        _interpolate: function(e) {
            var t,
            n,
            r,
            o = document.querySelector(":focus"),
            u = this.container.querySelectorAll(i),
            a = u.length,
            f = 0;
            for (; f < a; f++) {
                t = u[f];
                if (t === o) continue;
                if (e && t.type === "hidden") continue;
                n = t.getAttribute(s),
                r = this.elementToChange ? this.elementToChange[n] || "": t.defaultValue,
                t.value = r
            }
        },
        show: function(e) {
            var i = this,
            s = this.container.querySelector(r);
            this.elementToChange = e,
            this._observe(),
            this._interpolate(),
            e && (this.interval = setInterval(function() {
                i._interpolate(!0)
            },
            500)),
            t.addClass(this.link, n),
            this.container.style.display = "",
            this.fire("show");
            if (s && !e) try {
                s.focus()
            } catch(o) {}
        },
        hide: function() {
            clearInterval(this.interval),
            this.elementToChange = null,
            t.removeClass(this.link, n),
            this.container.style.display = "none",
            this.fire("hide")
        }
    })
} (wysihtml5),
function(e) {
    var t = e.dom,
    n = {
        position: "relative"
    },
    r = {
        left: 0,
        margin: 0,
        opacity: 0,
        overflow: "hidden",
        padding: 0,
        position: "absolute",
        top: 0,
        zIndex: 1
    },
    i = {
        cursor: "inherit",
        fontSize: "50px",
        height: "50px",
        marginTop: "-25px",
        outline: 0,
        padding: 0,
        position: "absolute",
        right: "-4px",
        top: "50%"
    },
    s = {
        "x-webkit-speech": "",
        speech: ""
    };
    e.toolbar.Speech = function(o, u) {
        var a = document.createElement("input");
        if (!e.browser.supportsSpeechApiOn(a)) {
            u.style.display = "none";
            return
        }
        var f = document.createElement("div");
        e.lang.object(r).merge({
            width: u.offsetWidth + "px",
            height: u.offsetHeight + "px"
        }),
        t.insert(a).into(f),
        t.insert(f).into(u),
        t.setStyles(i).on(a),
        t.setAttributes(s).on(a),
        t.setStyles(r).on(f),
        t.setStyles(n).on(u);
        var l = "onwebkitspeechchange" in a ? "webkitspeechchange": "speechchange";
        t.observe(a, l, 
        function() {
            o.execCommand("insertText", a.value),
            a.value = ""
        }),
        t.observe(a, "click", 
        function(e) {
            t.hasClass(u, "wysihtml5-command-disabled") && e.preventDefault(),
            e.stopPropagation()
        })
    }
} (wysihtml5),
function(e) {
    var t = "wysihtml5-command-disabled",
    n = "wysihtml5-commands-disabled",
    r = "wysihtml5-command-active",
    i = "wysihtml5-action-active",
    s = e.dom;
    e.toolbar.Toolbar = Base.extend({
        constructor: function(t, n) {
            this.editor = t,
            this.container = typeof n == "string" ? document.getElementById(n) : n,
            this.composer = t.composer,
            this._getLinks("command"),
            this._getLinks("action"),
            this._observe(),
            this.show();
            var r = this.container.querySelectorAll("[data-wysihtml5-command=insertSpeech]"),
            i = r.length,
            s = 0;
            for (; s < i; s++) new e.toolbar.Speech(this, r[s])
        },
        _getLinks: function(t) {
            var n = this[t + "Links"] = e.lang.array(this.container.querySelectorAll("[data-wysihtml5-" + t + "]")).get(),
            r = n.length,
            i = 0,
            s = this[t + "Mapping"] = {},
            o,
            u,
            a,
            f,
            l;
            for (; i < r; i++) o = n[i],
            a = o.getAttribute("data-wysihtml5-" + t),
            f = o.getAttribute("data-wysihtml5-" + t + "-value"),
            u = this.container.querySelector("[data-wysihtml5-" + t + "-group='" + a + "']"),
            l = this._getDialog(o, a),
            s[a + ":" + f] = {
                link: o,
                group: u,
                name: a,
                value: f,
                dialog: l,
                state: !1
            }
        },
        _getDialog: function(t, n) {
            var r = this,
            i = this.container.querySelector("[data-wysihtml5-dialog='" + n + "']"),
            s,
            o;
            return i && (s = new e.toolbar.Dialog(t, i), s.observe("show", 
            function() {
                o = r.composer.selection.getBookmark(),
                r.editor.fire("show:dialog", {
                    command: n,
                    dialogContainer: i,
                    commandLink: t
                })
            }), s.observe("save", 
            function(e) {
                o && r.composer.selection.setBookmark(o),
                r._execCommand(n, e),
                r.editor.fire("save:dialog", {
                    command: n,
                    dialogContainer: i,
                    commandLink: t
                })
            }), s.observe("cancel", 
            function() {
                r.editor.focus(!1),
                r.editor.fire("cancel:dialog", {
                    command: n,
                    dialogContainer: i,
                    commandLink: t
                })
            })),
            s
        },
        execCommand: function(e, t) {
            if (this.commandsDisabled) return;
            var n = this.commandMapping[e + ":" + t];
            n && n.dialog && !n.state ? n.dialog.show() : this._execCommand(e, t)
        },
        _execCommand: function(e, t) {
            this.editor.focus(!1),
            this.composer.commands.exec(e, t),
            this._updateLinkStates()
        },
        execAction: function(e) {
            var t = this.editor;
            switch (e) {
            case "change_view":
                t.currentView === t.textarea ? t.fire("change_view", "composer") : t.fire("change_view", "textarea")
            }
        },
        _observe: function() {
            var e = this,
            t = this.editor,
            r = this.container,
            i = this.commandLinks.concat(this.actionLinks),
            o = i.length,
            u = 0;
            for (; u < o; u++) s.setAttributes({
                href: "javascript:;",
                unselectable: "on"
            }).on(i[u]);
            s.delegate(r, "[data-wysihtml5-command]", "mousedown", 
            function(e) {
                e.preventDefault()
            }),
            s.delegate(r, "[data-wysihtml5-command]", "click", 
            function(t) {
                var n = this,
                r = n.getAttribute("data-wysihtml5-command"),
                i = n.getAttribute("data-wysihtml5-command-value");
                e.execCommand(r, i),
                t.preventDefault()
            }),
            s.delegate(r, "[data-wysihtml5-action]", "click", 
            function(t) {
                var n = this.getAttribute("data-wysihtml5-action");
                e.execAction(n),
                t.preventDefault()
            }),
            t.observe("focus:composer", 
            function() {
                e.bookmark = null,
                clearInterval(e.interval),
                e.interval = setInterval(function() {
                    e._updateLinkStates()
                },
                500)
            }),
            t.observe("blur:composer", 
            function() {
                clearInterval(e.interval)
            }),
            t.observe("destroy:composer", 
            function() {
                clearInterval(e.interval)
            }),
            t.observe("change_view", 
            function(t) {
                setTimeout(function() {
                    e.commandsDisabled = t !== "composer",
                    e._updateLinkStates(),
                    e.commandsDisabled ? s.addClass(r, n) : s.removeClass(r, n)
                },
                0)
            })
        },
        _updateLinkStates: function() {
            var n = this.composer.element,
            o = this.commandMapping,
            u = this.actionMapping,
            a,
            f,
            l,
            c;
            for (a in o) {
                c = o[a],
                this.commandsDisabled ? (f = !1, s.removeClass(c.link, r), c.group && s.removeClass(c.group, r), c.dialog && c.dialog.hide()) : (f = this.composer.commands.state(c.name, c.value), e.lang.object(f).isArray() && (f = f.length === 1 ? f[0] : !0), s.removeClass(c.link, t), c.group && s.removeClass(c.group, t));
                if (c.state === f) continue;
                c.state = f,
                f ? (s.addClass(c.link, r), c.group && s.addClass(c.group, r), c.dialog && (typeof f == "object" ? c.dialog.show(f) : c.dialog.hide())) : (s.removeClass(c.link, r), c.group && s.removeClass(c.group, r), c.dialog && c.dialog.hide())
            }
            for (a in u) l = u[a],
            l.name === "change_view" && (l.state = this.editor.currentView === this.editor.textarea, l.state ? s.addClass(l.link, i) : s.removeClass(l.link, i))
        },
        show: function() {
            this.container.style.display = ""
        },
        hide: function() {
            this.container.style.display = "none"
        }
    })
} (wysihtml5),
function(e) {
    var t,
    n = {
        name: t,
        style: !0,
        toolbar: t,
        autoLink: !0,
        parserRules: {
            tags: {
                br: {},
                span: {},
                div: {},
                p: {}
            },
            classes: {}
        },
        parser: e.dom.parse,
        composerClassName: "wysihtml5-editor",
        bodyClassName: "wysihtml5-supported",
        stylesheets: [],
        placeholderText: t,
        allowObjectResizing: !0,
        supportTouchDevices: !0
    };
    e.Editor = e.lang.Dispatcher.extend({
        constructor: function(t, r) {
            this.textareaElement = typeof t == "string" ? document.getElementById(t) : t,
            this.config = e.lang.object({}).merge(n).merge(r).get(),
            this.textarea = new e.views.Textarea(this, this.textareaElement, this.config),
            this.currentView = this.textarea,
            this._isCompatible = e.browser.supported();
            if (!this._isCompatible || !this.config.supportTouchDevices && e.browser.isTouchDevice()) {
                var i = this;
                setTimeout(function() {
                    i.fire("beforeload").fire("load")
                },
                0);
                return
            }
            e.dom.addClass(document.body, this.config.bodyClassName),
            this.composer = new e.views.Composer(this, this.textareaElement, this.config),
            this.currentView = this.composer,
            typeof this.config.parser == "function" && this._initParser(),
            this.observe("beforeload", 
            function() {
                this.synchronizer = new e.views.Synchronizer(this, this.textarea, this.composer),
                this.config.toolbar && (this.toolbar = new e.toolbar.Toolbar(this, this.config.toolbar))
            });
            try {
                console.log("Heya! This page is using wysihtml5 for rich text editing. Check out https://github.com/xing/wysihtml5")
            } catch(s) {}
        },
        isCompatible: function() {
            return this._isCompatible
        },
        clear: function() {
            return this.currentView.clear(),
            this
        },
        getValue: function(e) {
            return this.currentView.getValue(e)
        },
        setValue: function(e, t) {
            return e ? (this.currentView.setValue(e, t), this) : this.clear()
        },
        focus: function(e) {
            return this.currentView.focus(e),
            this
        },
        disable: function() {
            return this.currentView.disable(),
            this
        },
        enable: function() {
            return this.currentView.enable(),
            this
        },
        isEmpty: function() {
            return this.currentView.isEmpty()
        },
        hasPlaceholderSet: function() {
            return this.currentView.hasPlaceholderSet()
        },
        parse: function(t) {
            var n = this.config.parser(t, this.config.parserRules, this.composer.sandbox.getDocument(), !0);
            return typeof t == "object" && e.quirks.redraw(t),
            n
        },
        _initParser: function() {
            this.observe("paste:composer", 
            function() {
                var t = !0,
                n = this;
                n.composer.selection.executeAndRestore(function() {
                    e.quirks.cleanPastedHTML(n.composer.element),
                    n.parse(n.composer.element)
                },
                t)
            }),
            this.observe("paste:textarea", 
            function() {
                var e = this.textarea.getValue(),
                t;
                t = this.parse(e),
                this.textarea.setValue(t)
            })
        }
    })
} (wysihtml5),

//本地文件处理

function(e) {
    "use strict";
    var t = e.HTMLCanvasElement && e.HTMLCanvasElement.prototype,
    n = e.Blob && 
    function() {
        try {
            return Boolean(new Blob)
        } catch(e) {
            return ! 1
        }
    } (),
    r = n && e.Uint8Array && 
    function() {
        try {
            return (new Blob([new Uint8Array(100)])).size === 100
        } catch(e) {
            return ! 1
        }
    } (),
    i = e.BlobBuilder || e.WebKitBlobBuilder || e.MozBlobBuilder || e.MSBlobBuilder,
    s = (n || i) && e.atob && e.ArrayBuffer && e.Uint8Array && 
    function(e) {
        var t,
        s,
        o,
        u,
        a,
        f;
        e.split(",")[0].indexOf("base64") >= 0 ? t = atob(e.split(",")[1]) : t = decodeURIComponent(e.split(",")[1]),
        s = new ArrayBuffer(t.length),
        o = new Uint8Array(s);
        for (u = 0; u < t.length; u += 1) o[u] = t.charCodeAt(u);
        return a = e.split(",")[0].split(":")[1].split(";")[0],
        n ? new Blob([r ? o: s], {
            type: a
        }) : (f = new i, f.append(s), f.getBlob(a))
    };
    e.HTMLCanvasElement && !t.toBlob && (t.mozGetAsFile ? t.toBlob = function(e, t) {
        e(this.mozGetAsFile("blob", t))
    }: t.toDataURL && s && (t.toBlob = function(e, t) {
        e(s(this.toDataURL(t)))
    })),
    typeof define == "function" && define.amd ? define(function() {
        return s
    }) : e.dataURLtoBlob = s
} (this),

//某日历插件

function(e) {
    function O(e, t, n, r) {
        var i = n.lang();
        return i[e].call ? i[e](n, r) : i[e][t]
    }
    function M(e, t) {
        return function(n) {
            return B(e.call(this, n), t)
        }
    }
    function _(e) {
        return function(t) {
            var n = e.call(this, t);
            return n + this.lang().ordinal(n)
        }
    }
    function D(e, t, n) {
        this._d = e,
        this._isUTC = !!t,
        this._a = e._a || null,
        this._lang = n || !1
    }
    function P(e) {
        var t = this._data = {},
        n = e.years || e.y || 0,
        r = e.months || e.M || 0,
        i = e.weeks || e.w || 0,
        s = e.days || e.d || 0,
        o = e.hours || e.h || 0,
        u = e.minutes || e.m || 0,
        a = e.seconds || e.s || 0,
        f = e.milliseconds || e.ms || 0;
        this._milliseconds = f + a * 1e3 + u * 6e4 + o * 36e5,
        this._days = s + i * 7,
        this._months = r + n * 12,
        t.milliseconds = f % 1e3,
        a += H(f / 1e3),
        t.seconds = a % 60,
        u += H(a / 60),
        t.minutes = u % 60,
        o += H(u / 60),
        t.hours = o % 24,
        s += H(o / 24),
        s += i * 7,
        t.days = s % 30,
        r += H(s / 30),
        t.months = r % 12,
        n += H(r / 12),
        t.years = n,
        this._lang = !1
    }
    function H(e) {
        return e < 0 ? Math.ceil(e) : Math.floor(e)
    }
    function B(e, t) {
        var n = e + "";
        while (n.length < t) n = "0" + n;
        return n
    }
    function j(e, t, n) {
        var r = t._milliseconds,
        i = t._days,
        s = t._months,
        o;
        r && e._d.setTime( + e + r * n),
        i && e.date(e.date() + i * n),
        s && (o = e.date(), e.date(1).month(e.month() + s * n).date(Math.min(o, e.daysInMonth())))
    }
    function F(e) {
        return Object.prototype.toString.call(e) === "[object Array]"
    }
    function I(e, t) {
        var n = Math.min(e.length, t.length),
        r = Math.abs(e.length - t.length),
        i = 0,
        s;
        for (s = 0; s < n; s++)~~e[s] !== ~~t[s] && i++;
        return i + r
    }
    function q(e, t, n, r) {
        var i,
        s,
        o = [];
        for (i = 0; i < 7; i++) o[i] = e[i] = e[i] == null ? i === 2 ? 1: 0: e[i];
        return e[7] = o[7] = t,
        e[8] != null && (o[8] = e[8]),
        e[3] += n || 0,
        e[4] += r || 0,
        s = new Date(0),
        t ? (s.setUTCFullYear(e[0], e[1], e[2]), s.setUTCHours(e[3], e[4], e[5], e[6])) : (s.setFullYear(e[0], e[1], e[2]), s.setHours(e[3], e[4], e[5], e[6])),
        s._a = o,
        s
    }
    function R(e, n) {
        var r,
        i,
        o = []; ! n && u && (n = require("./lang/" + e));
        for (r = 0; r < a.length; r++) n[a[r]] = n[a[r]] || s.en[a[r]];
        for (r = 0; r < 12; r++) i = t([2e3, r]),
        o[r] = new RegExp("^" + (n.months[r] || n.months(i, "")) + "|^" + (n.monthsShort[r] || n.monthsShort(i, "")).replace(".", ""), "i");
        return n.monthsParse = n.monthsParse || o,
        s[e] = n,
        n
    }
    function U(e) {
        var n = typeof e == "string" && e || e && e._lang || null;
        return n ? s[n] || R(n) : t
    }
    function z(e) {
        return e.match(/\[.*\]/) ? e.replace(/^\[|\]$/g, "") : e.replace(/\\/g, "")
    }
    function W(e) {
        var t = e.match(l),
        n,
        r;
        for (n = 0, r = t.length; n < r; n++) A[t[n]] ? t[n] = A[t[n]] : t[n] = z(t[n]);
        return function(i) {
            var s = "";
            for (n = 0; n < r; n++) s += typeof t[n].call == "function" ? t[n].call(i, e) : t[n];
            return s
        }
    }
    function X(e, t) {
        function r(t) {
            return e.lang().longDateFormat[t] || t
        }
        var n = 5;
        while (n--&&c.test(t)) t = t.replace(c, r);
        return C[t] || (C[t] = W(t)),
        C[t](e)
    }
    function V(e) {
        switch (e) {
        case "DDDD":
            return v;
        case "YYYY":
            return m;
        case "S":
        case "SS":
        case "SSS":
        case "DDD":
            return d;
        case "MMM":
        case "MMMM":
        case "dd":
        case "ddd":
        case "dddd":
        case "a":
        case "A":
            return g;
        case "Z":
        case "ZZ":
            return y;
        case "T":
            return b;
        case "MM":
        case "DD":
        case "YY":
        case "HH":
        case "hh":
        case "mm":
        case "ss":
        case "M":
        case "D":
        case "d":
        case "H":
        case "h":
        case "m":
        case "s":
            return p;
        default:
            return new RegExp(e.replace("\\", ""))
        }
    }
    function $(e, t, n, r) {
        var i,
        s;
        switch (e) {
        case "M":
        case "MM":
            n[1] = t == null ? 0: ~~t - 1;
            break;
        case "MMM":
        case "MMMM":
            for (i = 0; i < 12; i++) if (U().monthsParse[i].test(t)) {
                n[1] = i,
                s = !0;
                break
            }
            s || (n[8] = !1);
            break;
        case "D":
        case "DD":
        case "DDD":
        case "DDDD":
            t != null && (n[2] = ~~t);
            break;
        case "YY":
            n[0] = ~~t + (~~t > 70 ? 1900: 2e3);
            break;
        case "YYYY":
            n[0] = ~~Math.abs(t);
            break;
        case "a":
        case "A":
            r.isPm = (t + "").toLowerCase() === "pm";
            break;
        case "H":
        case "HH":
        case "h":
        case "hh":
            n[3] = ~~t;
            break;
        case "m":
        case "mm":
            n[4] = ~~t;
            break;
        case "s":
        case "ss":
            n[5] = ~~t;
            break;
        case "S":
        case "SS":
        case "SSS":
            n[6] = ~~ (("0." + t) * 1e3);
            break;
        case "Z":
        case "ZZ":
            r.isUTC = !0,
            i = (t + "").match(x),
            i && i[1] && (r.tzh = ~~i[1]),
            i && i[2] && (r.tzm = ~~i[2]),
            i && i[0] === "+" && (r.tzh = -r.tzh, r.tzm = -r.tzm)
        }
        t == null && (n[8] = !1)
    }
    function J(e, t) {
        var n = [0, 0, 1, 0, 0, 0, 0],
        r = {
            tzh: 0,
            tzm: 0
        },
        i = t.match(l),
        s,
        o;
        for (s = 0; s < i.length; s++) o = (V(i[s]).exec(e) || [])[0],
        o && (e = e.slice(e.indexOf(o) + o.length)),
        A[i[s]] && $(i[s], o, n, r);
        return r.isPm && n[3] < 12 && (n[3] += 12),
        r.isPm === !1 && n[3] === 12 && (n[3] = 0),
        q(n, r.isUTC, r.tzh, r.tzm)
    }
    function K(e, t) {
        var n,
        r = e.match(h) || [],
        i,
        s = 99,
        o,
        u,
        a;
        for (o = 0; o < t.length; o++) u = J(e, t[o]),
        i = X(new D(u), t[o]).match(h) || [],
        a = I(r, i),
        a < s && 
        (s = a, n = u);
        return n
    }
    function Q(e) {
        var t = "YYYY-MM-DDT",
        n;
        if (w.exec(e)) {
            for (n = 0; n < 4; n++) if (S[n][1].exec(e)) {
                t += S[n][0];
                break
            }
            return y.exec(e) ? J(e, t + " Z") : J(e, t)
        }
        return new Date(e)
    }
    function G(e, t, n, r, i) {
        var s = i.relativeTime[e];
        return typeof s == "function" ? s(t || 1, !!n, e, r) : s.replace(/%d/i, t || 1)
    }
    function Y(e, t, n) {
        var i = r(Math.abs(e) / 1e3),
        s = r(i / 60),
        o = r(s / 60),
        u = r(o / 24),
        a = r(u / 365),
        f = i < 45 && ["s", i] || s === 1 && ["m"] || s < 45 && ["mm", s] || o === 1 && ["h"] || o < 22 && ["hh", o] || u === 1 && ["d"] || u <= 25 && ["dd", u] || u <= 45 && ["M"] || u < 345 && ["MM", r(u / 30)] || a === 1 && ["y"] || ["yy", a];
        return f[2] = t,
        f[3] = e > 0,
        f[4] = n,
        G.apply({},
        f)
    }
    function Z(e, n) {
        t.fn[e] = function(e) {
            var t = this._isUTC ? "UTC": "";
            return e != null ? (this._d["set" + t + n](e), this) : this._d["get" + t + n]()
        }
    }
    function et(e) {
        t.duration.fn[e] = function() {
            return this._data[e]
        }
    }
    function tt(e, n) {
        t.duration.fn["as" + e] = function() {
            return + this / n
        }
    }
    var t,
    n = "1.7.2",
    r = Math.round,
    i,
    s = {},
    o = "en",
    u = typeof module != "undefined" && module.exports,
    a = "months|monthsShort|weekdays|weekdaysShort|weekdaysMin|longDateFormat|calendar|relativeTime|ordinal|meridiem".split("|"),
    f = /^\/?Date\((\-?\d+)/i,
    l = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|SS?S?|zz?|ZZ?|.)/g,
    c = /(\[[^\[]*\])|(\\)?(LT|LL?L?L?)/g,
    h = /([0-9a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)/gi,
    p = /\d\d?/,
    d = /\d{1,3}/,
    v = /\d{3}/,
    m = /\d{1,4}/,
    g = /[0-9a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+/i,
    y = /Z|[\+\-]\d\d:?\d\d/i,
    b = /T/i,
    w = /^\s*\d{4}-\d\d-\d\d(T(\d\d(:\d\d(:\d\d(\.\d\d?\d?)?)?)?)?([\+\-]\d\d:?\d\d)?)?/,
    E = "YYYY-MM-DDTHH:mm:ssZ",
    S = [["HH:mm:ss.S", /T\d\d:\d\d:\d\d\.\d{1,3}/], ["HH:mm:ss", /T\d\d:\d\d:\d\d/], ["HH:mm", /T\d\d:\d\d/], ["HH", /T\d\d/]],
    x = /([\+\-]|\d\d)/gi,
    T = "Month|Date|Hours|Minutes|Seconds|Milliseconds".split("|"),
    N = {
        Milliseconds: 1,
        Seconds: 1e3,
        Minutes: 6e4,
        Hours: 36e5,
        Days: 864e5,
        Months: 2592e6,
        Years: 31536e6
    },
    C = {},
    k = "DDD w M D d".split(" "),
    L = "M D H h m s w".split(" "),
    A = {
        M: function() {
            return this.month() + 1
        },
        MMM: function(e) {
            return O("monthsShort", this.month(), this, e)
        },
        MMMM: function(e) {
            return O("months", this.month(), this, e)
        },
        D: function() {
            return this.date()
        },
        DDD: function() {
            var e = new Date(this.year(), this.month(), this.date()),
            t = new Date(this.year(), 0, 1);
            return~~ ((e - t) / 864e5 + 1.5)
        },
        d: function() {
            return this.day()
        },
        dd: function(e) {
            return O("weekdaysMin", this.day(), this, e)
        },
        ddd: function(e) {
            return O("weekdaysShort", this.day(), this, e)
        },
        dddd: function(e) {
            return O("weekdays", this.day(), this, e)
        },
        w: function() {
            var e = new Date(this.year(), this.month(), this.date() - this.day() + 5),
            t = new Date(e.getFullYear(), 0, 4);
            return~~ ((e - t) / 864e5 / 7 + 1.5)
        },
        YY: function() {
            return B(this.year() % 100, 2)
        },
        YYYY: function() {
            return B(this.year(), 4)
        },
        a: function() {
            return this.lang().meridiem(this.hours(), this.minutes(), !0)
        },
        A: function() {
            return this.lang().meridiem(this.hours(), this.minutes(), !1)
        },
        H: function() {
            return this.hours()
        },
        h: function() {
            return this.hours() % 12 || 12
        },
        m: function() {
            return this.minutes()
        },
        s: function() {
            return this.seconds()
        },
        S: function() {
            return~~ (this.milliseconds() / 100)
        },
        SS: function() {
            return B(~~ (this.milliseconds() / 10), 2)
        },
        SSS: function() {
            return B(this.milliseconds(), 3)
        },
        Z: function() {
            var e = -this.zone(),
            t = "+";
            return e < 0 && (e = -e, t = "-"),
            t + B(~~ (e / 60), 2) + ":" + B(~~e % 60, 2)
        },
        ZZ: function() {
            var e = -this.zone(),
            t = "+";
            return e < 0 && (e = -e, t = "-"),
            t + B(~~ (10 * e / 6), 4)
        }
    };
    while (k.length) i = k.pop(),
    A[i + "o"] = _(A[i]);
    while (L.length) i = L.pop(),
    A[i + i] = M(A[i], 2);
    A.DDDD = M(A.DDD, 3),
    t = function(n, r) {
        if (n === null || n === "") return null;
        var i,
        s;
        return t.isMoment(n) ? new D(new Date( + n._d), n._isUTC, n._lang) : (r ? F(r) ? i = K(n, r) : i = J(n, r) : (s = f.exec(n), i = n === e ? new Date: s ? new Date( + s[1]) : n instanceof Date ? n: F(n) ? q(n) : typeof n == "string" ? Q(n) : new Date(n)), new D(i))
    },
    t.utc = function(e, n) {
        return F(e) ? new D(q(e, !0), !0) : (typeof e == "string" && !y.exec(e) && (e += " +0000", n && (n += " Z")), t(e, n).utc())
    },
    t.unix = function(e) {
        return t(e * 1e3)
    },
    t.duration = function(e, n) {
        var r = t.isDuration(e),
        i = typeof e == "number",
        s = r ? e._data: i ? {}: e,
        o;
        return i && (n ? s[n] = e: s.milliseconds = e),
        o = new P(s),
        r && (o._lang = e._lang),
        o
    },
    t.humanizeDuration = function(e, n, r) {
        return t.duration(e, n === !0 ? null: n).humanize(n === !0 ? !0: r)
    },
    t.version = n,
    t.defaultFormat = E,
    t.lang = function(e, n) {
        var r;
        if (!e) return o; (n || !s[e]) && R(e, n);
        if (s[e]) {
            for (r = 0; r < a.length; r++) t[a[r]] = s[e][a[r]];
            t.monthsParse = s[e].monthsParse,
            o = e
        }
    },
    t.langData = U,
    t.isMoment = function(e) {
        return e instanceof D
    },
    t.isDuration = function(e) {
        return e instanceof P
    },
    t.lang("en", {
        months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"),
        monthsShort: "Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),
        weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),
        weekdaysShort: "Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),
        weekdaysMin: "Su_Mo_Tu_We_Th_Fr_Sa".split("_"),
        longDateFormat: {
            LT: "h:mm A",
            L: "MM/DD/YYYY",
            LL: "MMMM D YYYY",
            LLL: "MMMM D YYYY LT",
            LLLL: "dddd, MMMM D YYYY LT"
        },
        meridiem: function(e, t, n) {
            return e > 11 ? n ? "pm": "PM": n ? "am": "AM"
        },
        calendar: {
            sameDay: "[Today at] LT",
            nextDay: "[Tomorrow at] LT",
            nextWeek: "dddd [at] LT",
            lastDay: "[Yesterday at] LT",
            lastWeek: "[last] dddd [at] LT",
            sameElse: "L"
        },
        relativeTime: {
            future: "in %s",
            past: "%s ago",
            s: "a few seconds",
            m: "a minute",
            mm: "%d minutes",
            h: "an hour",
            hh: "%d hours",
            d: "a day",
            dd: "%d days",
            M: "a month",
            MM: "%d months",
            y: "a year",
            yy: "%d years"
        },
        ordinal: function(e) {
            var t = e % 10;
            return~~ (e % 100 / 10) === 1 ? "th": t === 1 ? "st": t === 2 ? "nd": t === 3 ? "rd": "th"
        }
    }),
    t.fn = D.prototype = {
        clone: function() {
            return t(this)
        },
        valueOf: function() {
            return + this._d
        },
        unix: function() {
            return Math.floor( + this._d / 1e3)
        },
        toString: function() {
            return this._d.toString()
        },
        toDate: function() {
            return this._d
        },
        toArray: function() {
            var e = this;
            return [e.year(), e.month(), e.date(), e.hours(), e.minutes(), e.seconds(), e.milliseconds(), !!this._isUTC]
        },
        isValid: function() {
            return this._a ? this._a[8] != null ? !!this._a[8] : !I(this._a, (this._a[7] ? t.utc(this._a) : t(this._a)).toArray()) : !isNaN(this._d.getTime())
        },
        utc: function() {
            return this._isUTC = !0,
            this
        },
        local: function() {
            return this._isUTC = !1,
            this
        },
        format: function(e) {
            return X(this, e ? e: t.defaultFormat)
        },
        add: function(e, n) {
            var r = n ? t.duration( + n, e) : t.duration(e);
            return j(this, r, 1),
            this
        },
        subtract: function(e, n) {
            var r = n ? t.duration( + n, e) : t.duration(e);
            return j(this, r, -1),
            this
        },
        diff: function(e, n, i) {
            var s = this._isUTC ? t(e).utc() : t(e).local(),
            o = (this.zone() - s.zone()) * 6e4,
            u = this._d - s._d - o,
            a = this.year() - s.year(),
            f = this.month() - s.month(),
            l = this.date() - s.date(),
            c;
            return n === "months" ? c = a * 12 + f + l / 30: n === "years" ? c = a + (f + l / 30) / 12: c = n === "seconds" ? u / 1e3: n === "minutes" ? u / 6e4: n === "hours" ? u / 36e5: n === "days" ? u / 864e5: n === "weeks" ? u / 6048e5: u,
            i ? c: r(c)
        },
        from: function(e, n) {
            return t.duration(this.diff(e)).lang(this._lang).humanize(!n)
        },
        fromNow: function(e) {
            return this.from(t(), e)
        },
        calendar: function() {
            var e = this.diff(t().sod(), "days", !0),
            n = this.lang().calendar,
            r = n.sameElse,
            i = e < -6 ? r: e < -1 ? n.lastWeek: e < 0 ? n.lastDay: e < 1 ? n.sameDay: e < 2 ? n.nextDay: e < 7 ? n.nextWeek: r;
            return this.format(typeof i == "function" ? i.apply(this) : i)
        },
        isLeapYear: function() {
            var e = this.year();
            return e % 4 === 0 && e % 100 !== 0 || e % 400 === 0
        },
        isDST: function() {
            return this.zone() < t([this.year()]).zone() || this.zone() < t([this.year(), 5]).zone()
        },
        day: function(e) {
            var t = this._isUTC ? this._d.getUTCDay() : this._d.getDay();
            return e == null ? t: this.add({
                d: e - t
            })
        },
        startOf: function(e) {
            switch (e.replace(/s$/, "")) {
            case "year":
                this.month(0);
            case "month":
                this.date(1);
            case "day":
                this.hours(0);
            case "hour":
                this.minutes(0);
            case "minute":
                this.seconds(0);
            case "second":
                this.milliseconds(0)
            }
            return this
        },
        endOf: function(e) {
            return this.startOf(e).add(e.replace(/s?$/, "s"), 1).subtract("ms", 1)
        },
        sod: function() {
            return this.clone().startOf("day")
        },
        eod: function() {
            return this.clone().endOf("day")
        },
        zone: function() {
            return this._isUTC ? 0: this._d.getTimezoneOffset()
        },
        daysInMonth: function() {
            return t.utc([this.year(), this.month() + 1, 0]).date()
        },
        lang: function(t) {
            return t === e ? U(this) : (this._lang = t, this)
        }
    };
    for (i = 0; i < T.length; i++) Z(T[i].toLowerCase(), T[i]);
    Z("year", "FullYear"),
    t.duration.fn = P.prototype = {
        weeks: function() {
            return H(this.days() / 7)
        },
        valueOf: function() {
            return this._milliseconds + this._days * 864e5 + this._months * 2592e6
        },
        humanize: function(e) {
            var t = +this,
            n = this.lang().relativeTime,
            r = Y(t, !e, this.lang()),
            i = t <= 0 ? n.past: n.future;
            return e && (typeof i == "function" ? r = i(r) : r = i.replace(/%s/i, r)),
            r
        },
        lang: t.fn.lang
    };
    for (i in N) N.hasOwnProperty(i) && (tt(i, N[i]), et(i.toLowerCase()));
    tt("Weeks", 6048e5),
    u && (module.exports = t),
    typeof ender == "undefined" && (this.moment = t),
    typeof define == "function" && define.amd && define("moment", [], 
    function() {
        return t
    })
}.call(this),

//MCW框架，绑定事件，AJAX setup

function(t) {
    t(function() {
        moment.weekdays = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
		//AJAX启动项
        t.ajaxSetup({
            type: "POST",
            dataType: "json",
            data: {
                conn_guid: t("#conn-guid").val()
            },
            beforeSend: function(e, n) {
                if (n.type != "GET") {
                    var r = t("meta[name='csrf-token']").attr("content");
                    e.setRequestHeader("X-CSRF-Token", r)
                }
            },
            error: function(e, n, r) {
                if (n === "abort") return;
                var i = t.parseJSON(e.responseText),
                s = "";
                i.errors ? t.each(i.errors, 
                function(e, t) {
                    s += t.msg + "<br/>"
                }) : s += i.msg,
                s && mcw.message({
                    msg: s
                });
                var o = mcw.urlParts(location.href).href;
                mcw.clearPageCache(o)
            }
        }),
		//body的一些事件绑定
        t.rails && t("body").on("keydown", "form.form textarea", 
        function(e) {
            //当表单中textarea在按下回车键时候进行提交
            var n = mcw.metaKey(e);
            n && e.which == 13 && (e.preventDefault(), t(this).closest("form.form").submit())
        }).on("submit", "form.form", 
        function(e) {
            //表单提交时候进行指定的input和textarea验证
            var n = t(e.currentTarget),
            r = !0;
            return n.find("input[data-validate], textarea[data-validate]").each(function(e, n) {
                mcw.validateField(t(n)) || (r = !1)
            }),
            r
        }).on("blur", "input[data-validate]", 
        function(e) {
            //表单元素当失去焦点时候，进行判断然后数据验证
            var n = t(this);
            n.attr("data-blur-validate") != "false" && mcw.validateField(n, !0)
        }).on("ajax:error", "form.form", 
        function(e, n) {
            //表单提交错误则显示错误
            var r = t(e.currentTarget),
            i = t.parseJSON(n.responseText).errors;
            t.each(i, 
            function(e, n) {
                var i = r.find("input[name=" + n.target + "], textarea[name=" + n.target + "]"),
                s = i.nextAll(".error");
                s.length || (s = t("<p class='error'></p>").insertAfter(i)),
                s.text(n.msg),
                i.addClass("error").nextAll(".desc").hide()
            })
        }).on("ajax:complete", "form.form", 
        function(e, n, r) {
            //表单完成，先显示成功，进行URL判断，如果没有跳转也没刷新则还原为可以可提交状态
            if (r == "success") {
                var i = t(this).find(t.rails.enableSelector),
                s = i.attr("data-success-text"),
                o = t.parseJSON(n.responseText),
                u = o && o.target_url || i.attr("data-goto"),
                a = i.data("refresh");
                s && i.text(s + " ✓").prop("disabled", !0).addClass("success");
                if (u) {
                    var f = mcw.urlParts(u),
                    l = mcw.urlParts(location.href);
                    f.path != l.path && (t(".workspace").length ? mcw.stack({
                        url: u,
                        replace: !0,
                        root: i.is("[data-goto-root]"),
                        restorePosition: !0
                    }) : location.href = u)
                }
                a && mcw.stack({
                    url: location.href,
                    nocache: !0
                }),
                s && !u && !a && setTimeout(function() {
                    i.text(i.data("ujs:enable-with")).prop("disabled", !1).removeClass("success")
                },
                3e3);
                if (s || u || a) return ! 1
            }
        }).on("ajax:complete", t.rails.linkClickSelector, 
        function(e, n, r) {
            //连接完成则隐藏加载中...，并且进行跳转判断
            var i = t(this);
            i.is("[data-global-loading]") ? mcw.globalLoading("hide") : i.is("[data-loading]") && mcw.tinyLoading(i, !1);
            if (r == "success") {
                var s = t.parseJSON(n.responseText),
                o = s && s.target_url || i.attr("data-goto"),
                u = i.data("refresh");
                if (o) {
                    var a = mcw.urlParts(o),
                    f = mcw.urlParts(location.href);
                    a.path != f.path && (t(".workspace").length ? mcw.stack({
                        url: o,
                        replace: !0,
                        root: i.is("[data-goto-root]"),
                        restorePosition: !0,
                        bare: i.is("[data-goto-bare]")
                    }) : location.href = o)
                }
                u && mcw.stack({
                    url: location.href,
                    nocache: !0
                })
            }
        }).on("ajax:error", t.rails.linkClickSelector, 
        function(e, n, r, i) {
            //连接错误则弹出错误
            if (r === "abort") return;
            var s = t.parseJSON(n.responseText),
            o = "";
            s.errors ? t.each(s.errors, 
            function(e, t) {
                o += t.msg + "<br/>"
            }) : o += s.msg,
            mcw.message({
                msg: o
            })
        }).on("ajax:beforeSend", t.rails.linkClickSelector, 
        function(e, n, r) {
            //加载连接之前显示加载中...效果
            var i = t(this);
            i.is("[data-global-loading]") ? mcw.globalLoading(i.data("global-loading")) : i.is("[data-loading]") && mcw.tinyLoading(i)
        })
    }),
	//核心mcw框架
    window.mcw = {
		//异步加载图片
        loadImage: function(e, t) {
            var n = new Image;
            t && (n.onload = function() {
                t(n)
            },
            n.onerror = function() {
                t()
            });
            if (typeof e == "string") n.src = e;
            else if (e.nodeName && e.nodeName == "IMG") n.src = e.src;
            else if (window.FileReader && FileReader.prototype.readAsDataURL) {
                var r = new FileReader;
                r.onload = function(e) {
                    n.src = e.target.result
                },
                r.readAsDataURL(e)
            } else t()
        },
		//批量预加载
        preloadImages: function(e) {
            t.each(e, 
            function(e, t) {
                mcw.loadImage(t)
            })
        },
		//模板标记解析
        template: function(e, n) {
            var r = t("#" + e).html();
            return n && t.each(n, 
            function(e, t) {
                var n = new RegExp("\\{\\{ " + e + " \\}\\}", "g");
                r = r.replace(n, t)
            }),
            t(r)
        },
		//参数匹配
        params: function(e) {
            e = e.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
            var t = "[\\?&]" + e + "=([^&#]*)",
            n = new RegExp(t),
            r = n.exec(window.location.search);
            return r ? decodeURIComponent(r[1].replace(/\+/g, " ")) : ""
        },
        //解析data-params
        parseParams: function(t) {
            if (!t) return null;
            var n = /([^&=]+)=?([^&]*)/g,
            r = /\+/g,
            i = function(e) {
                return decodeURIComponent(e.replace(r, " "))
            };
            params = {},
            e;
            while (e = n.exec(t)) {
                var s = i(e[1]),
                o = i(e[2]);
                s.substring(s.length - 2) === "[]" ? (s = s.substring(0, s.length - 2), (params[s] || (params[s] = [])).push(o)) : params[s] = o
            }
            return params
        },
		//路由解析
        urlParts: function(e) {
            if (!e) return null;
            var n = t("<a/>", {
                href: e
            }),
            //去掉两头的/,并添加
            r = "/" + n[0].pathname.replace(/\/$/g, "").replace(/^\//g, "") + "/",
            i = n[0].search,
            s = n[0].hash;
            return {
                href: r + i + s,
                path: r,
                search: i,
                hash: s
            }
        },
		//支持Transition效果
        supportTransition: function() {
            var e = document.body || document.documentElement,
            t = e.style,
            n = "transition";
            if (typeof t[n] == "string") return ! 0;
            v = ["Moz", "Webkit", "Khtml", "O", "ms"],
            n = n.charAt(0).toUpperCase() + n.substr(1);
            for (var r = 0; r < v.length; r++) if (typeof t[v[r] + n] == "string") return ! 0;
            return ! 1
        },
        transitionEnd: function(e, n) {
            if (mcw.supportTransition()) {
                var r = "transitionend";
                t.browser.webkit ? r = "webkitTransitionEnd": t.browser.msie ? r = "transitionend": t.browser.opera && (r = "oTransitionEnd"),
                e.one(r, n)
            } else setTimeout(n, 20)
        },
		//对话框
        dialog: function() {
            if (typeof arguments[0] == "string" && arguments[0] == "hide") return t(document).off(".dialog"),
            t("#mask").remove(),
            t(".dialog").remove();
            if (typeof arguments[0] == "object") {
                var e = t.extend({
                    el: null,
                    width: 600,
                    height: "auto",
                    modal: !1,
                    padding: !0,
                    closeButton: !0
                },
                arguments[0]);
                mcw.dialog("hide");
                var n = t("<div class='dialog'><div class='dialog-wrapper clearfix'></div><a href='javascript:;' class='link-close-dialog'>Close</a></div>").css({
                    width: e.width,
                    height: e.height
                }).appendTo(".page:last");
                e.closeButton || n.find(".link-close-dialog").remove(),
                n.find(".dialog-wrapper").append(e.el),
                n.find(".link-close-dialog").on("click", 
                function(e) {
                    e.preventDefault(),
                    mcw.dialog("hide")
                }),
                t(document).on("keydown.dialog", 
                function(e) {
                    e.which == 27 && mcw.dialog("hide")
                }),
                setTimeout(function() {
                    n.css({
                        marginLeft: -e.width / 2,
                        marginTop: -n.height() / 2
                    })
                },
                20);
                if (e.modal) {
                    var r = t("<div id='mask' class='hidden'></div>").appendTo(".page:last");
                    r.on("click", 
                    function(e) {
                        mcw.dialog("hide")
                    }),
                    setTimeout(function() {
                        r.removeClass("hidden")
                    },
                    20)
                }
                return n
            }
            return null
        },
		//提示框
        message: function(e) {
            var n = t("<div class='message-content'><p></p><div class='dialog-buttons clearfix'><button class='btn'></button></div></div>");
            n.find("p").html(e.msg),
            n.find(".dialog-buttons button").text(e.ok || "我知道了").on("click", 
            function(e) {
                mcw.dialog("hide")
            }),
            mcw.dialog(t.extend({
                el: n,
                width: 450
            },
            e))
        },
		//确认框
        confirm: function(e) {
            var n = t("<div class='message-content'><p></p><div class='dialog-buttons clearfix'><button class='btn btn-primary btn-yes'></button><a href='javascript:void(0)' class='link-no'></a></div></div>");
            n.find("p").html(e.msg),
            n.find(".dialog-buttons .btn-yes").text(e.ok || "确定").on("click", 
            function(t) {
                mcw.dialog("hide"),
                e.callback(!0, t)
            }),
            n.find(".dialog-buttons .link-no").text(e.cancel || "取消").on("click", 
            function(t) {
                t.preventDefault(),
                mcw.dialog("hide"),
                e.callback(!1, t)
            }),
            mcw.dialog(t.extend({
                el: n,
                width: 450
            },
            e))
        },
		//全局加载图标
        globalLoading: function(e) {
            if (e == "hide") t("#mask, .global-loading").remove();
            else {
                var n = t("<div id='mask' class='hidden'></div>").appendTo("body"),
                r = t("<div class='global-loading'>" + e + "</div>").appendTo("body");
                setTimeout(function() {
                    n && n.css({
                        cursor: "default"
                    }).removeClass("hidden"),
                    r && r.css({
                        marginLeft: -r.outerWidth() * .5,
                        marginTop: -r.outerHeight() * .5
                    })
                },
                20)
            }
        },
		//指派人时候小块内容加载
        tinyLoading: function(e, n) {
            e = t(e),
            n !== !1 ? (t("<img />", {
                src: "/assets/blank-3dbe121a376a181f0fe840fb1daeeb51.gif"
            }).css({
                display: e.css("display"),
                width: e.outerWidth(),
                height: e.outerHeight(),
                marginLeft: e.css("marginLeft"),
                marginTop: e.css("marginTop"),
                marginRight: e.css("marginRight"),
                marginBottom: e.css("marginBottom"),
                "float": e.css("float"),
                position: e.css("position"),
                top: e.css("top"),
                left: e.css("left"),
                verticalAlign: "bottom",
                background: "url(/assets/tiny-loading-e8bd9af828c29751e76f3d73d4f9e005.gif) no-repeat 50% 50%"
            }).addClass("tiny-loading").insertAfter(e), e.hide()) : (e.next(".tiny-loading").remove(), e.show())
        },
		//以对象方式处理文本
        selectText: function(e, n, r) {
            e = t(e),
            n = n || e.val().length,
            r = r || 0;
            if (e[0].createTextRange) {
                var i = e[0].createTextRange();
                i.collapse(!0),
                i.moveStart("character", n),
                i.moveEnd("character", r),
                i.select()
            } else e[0].setSelectionRange && e[0].setSelectionRange(n, n + r);
            e.focus()
        },
		//提示工具
        tooltip: function(e, n) {
            if (navigator.platform.indexOf("iPhone") != -1 || navigator.platform.indexOf("iPod") != -1 || navigator.platform.indexOf("iPad") != -1) return;
            if (n == "hide") {
                var r = e.data("tooltipTimer"),
                i = e.data("tooltipEl");
                r && (clearTimeout(r), r = null),
                i && (i.remove(), i = null)
            } else {
                var r = e.data("tooltipTimer"),
                i = e.data("tooltipEl"),
                s = e.offset(),
                o = e.width(),
                u = e.height(),
                a = e.attr("tooltip");
                r && (clearTimeout(r), r = null),
                i && (i.remove(), i = null),
                i = t("<div class='tooltip'><div class='tooltip-arrow'></div><div class='tooltip-content'></div></div>").appendTo("body"),
                i.find(".tooltip-content").text(a),
                i.css({
                    opacity: 0,
                    top: s.top + u,
                    left: s.left - (i.width() - o) * .5
                }),
                r = setTimeout(function() {
                    i.addClass("transition").css({
                        opacity: 1,
                        top: s.top + u + 15
                    })
                },
                200),
                e.data("tooltipTimer", r),
                e.data("tooltipEl", i)
            }
        },
		//自适应尺寸
        fitSize: function(e, n, r) {
            r = t.extend({
                stretch: !1,
                minWidth: 0,
                minHeight: 0
            },
            r);
            var i = {
                width: n.width,
                height: n.height
            };
            if (r.stretch || n.width > e.width || n.height > e.height || n.width < r.minWidth || n.height < r.minHeight) n.width / n.height > e.width / e.height ? (i.width = Math.max(e.width, r.minWidth), i.height = i.width * n.height / n.width) : (i.height = Math.max(e.height, r.minHeight), i.width = i.height * n.width / n.height);
            return i.x = (e.width - i.width) / 2,
            i.y = (e.height - i.height) / 2,
            i
        },
		//图片显示效果及延迟加载
        viewImage: function(e) {
            function g(e, n) {
                if (!c) return;
                var r = t(window),
                i = mcw.fitSize({
                    width: r.width() - 80,
                    height: r.height() - (v.length > 1 ? 160: 80)
                },
                n || {
                    width: e.width,
                    height: e.height
                });
                i.x += 40,
                i.y += 30,
                c.css({
                    width: i.width,
                    height: i.height,
                    top: i.y,
                    left: i.x
                }).find("img").attr({
                    src: e.src
                }),
                c.removeClass("loading"),
                p.show()
            }
            function y() {
                p.hide();
                var e = t(document).scrollTop(),
                r = t(document).scrollLeft(),
                i = {
                    width: n.width(),
                    height: n.height(),
                    top: n.offset().top - e,
                    left: n.offset().left - r
                };
                c.css(i),
                mcw.transitionEnd(c, 
                function(e) {
                    f.trigger("galleryhide").remove(),
                    c = null
                }),
                t(document).unbind(".originimg")
            }
            var n = e,
            r = e.data("origin-src"),
            i = e.data("origin-size"),
            s = e.data("origin-name");
            if (!r) return;
            n.is("[src]") || (n = n.find("[src]:first")),
            i ? (i = i.split(","), i = {
                width: i[0] * 1 || n.width() * 10,
                height: i[1] * 1 || n.height() * 10
            }) : i = {
                width: n.width() * 10,
                height: n.height() * 10
            };
            var o = t(document).scrollTop(),
            u = t(document).scrollLeft(),
            a = {
                width: n.width(),
                height: n.height(),
                top: n.offset().top - o,
                left: n.offset().left - u
            },
            f = t("<div />", {
                "class": "gallery-wrapper loading"
            }).click(t.proxy(y, this)).appendTo("body"),
            l = t("<div class='mask'></div>").appendTo(f),
            c = t("<div />", {
                id: "gallery-img"
            }).css({
                width: a.width,
                height: a.height,
                top: a.top,
                left: a.left
            }).appendTo(f),
            h = t("<img />", {
                src: n.attr("src")
            }).appendTo(c),
            p = t("<div />", {
                "class": "gallery-img-name hide",
                html: "<span>" + s + '</span> [ <a href="' + r + '" target="_blank">查看原图</a> ] '
            }).appendTo(c),
            d = t("<div />", {
                "class": "loading-indicator"
            }).appendTo(c),
            v = e.parent().children("*[data-origin-src]"),
            m = null;
            return v.length > 1 && (m = t("<ul/>", {
                "class": "gallery"
            }).appendTo(f), v.each(function(e, r) {
                var i = t(r),
                s;
                i.is("[src]") ? s = i: s = i.find("[src]:first");
                var o = t("<li/>"),
                u = t("<a/>", {
                    href: "javascript:;"
                }).appendTo(o),
                a = t("<img/>", {
                    src: s.attr("src")
                }).appendTo(u);
                u.on("click", {
                    d: i,
                    t: s
                },
                function(e) {
                    var t = e.data.d,
                    r = e.data.t;
                    return n = r,
                    p.hide(),
                    u.parent("li").addClass("selected").siblings("li").removeClass("selected"),
                    p.find("span").text(t.data("origin-name")).end().find("a").attr("href", t.data("origin-src")),
                    c.addClass("loading"),
                    mcw.loadImage(t.data("origin-src"), 
                    function(e) {
                        g(e)
                    }),
                    !1
                }),
                s[0] == n[0] && o.addClass("selected"),
                m.append(o)
            })),
            t(document).on("keydown.originimg", t.proxy(function(e) {
                return e.which == 27 ? y.call(this) : e.which == 37 || e.which == 38 ? m.find(".selected").prev("li").find("a").click() : (e.which == 39 || e.which == 40) && m.find(".selected").next("li").find("a").click(),
                !1
            },
            this)),
            t("span, a", p).on("click", 
            function(e) {
                e.stopPropagation()
            }),
            setTimeout(function() {
                mcw.loadImage(n.attr("src"), 
                function(e) {
                    if (!e) return f.remove(),
                    !1;
                    mcw.transitionEnd(c, 
                    function(e) {
                        f.trigger("galleryshow"),
                        c.addClass("loading"),
                        mcw.loadImage(r, 
                        function(e) {
                            c.removeClass("loading").find("img").attr("src", e.src)
                        }),
                        m && m.css({
                            left: (t(window).width() - m.width()) / 2
                        }),
                        p.show()
                    }),
                    g(e, i),
                    p.hide(),
                    f.removeClass("loading")
                })
            },
            20),
            f
        },
		//滚动效果
        scrollTo: function(e, n) {
            n = t.extend({
                anim: !0,
                container: null
            },
            n);
            var r = null,
            i = n.container ? t(n.container) : t("html, body");
            if (typeof e != "object" || typeof e.top != "number" && typeof e.left != "number") {
                var s = t(e).offset(),
                o = i.offset() || {
                    top: 0,
                    left: 0
                };
                r = {
                    top: s.top - o.top - 30,
                    left: s.left - o.left - 30
                }
            } else r = e;
            n.anim ? i.animate({
                scrollTop: r.top,
                scrollLeft: r.left
            },
            500) : i.scrollTop(r.top).scrollLeft(r.left)
        },
		//验证渲染
        validateField: function(e, n) {
            var r = e.attr("data-validate"),
            i = e.attr("data-validate-msg"),
            s = e.val(),
            o = !0,
            u = "";
            if (!r) return o;
            r = r.split(";"),
            i !== undefined && (i = i.split(";")),
            t.each(r, 
            function(r, a) {
                var a = t.trim(a).split(":"),
                f = a[0],
                l = a.length > 1 ? a[1] : null,
                c = null;
                if (f == "custom") {
                    var h = t.Event("validate");
                    e.trigger(h, [s, l]),
                    c = h.result || {
                        valid: !0
                    }
                } else c = mcw.validate[f](s, l);
                if (!c.valid) return o = c.valid,
                i && i.length && i[r] ? u = i[r] : c.errorMsg ? u = c.errorMsg: u = "",
                f == "required" && n && (o = !0, u = ""),
                !1
            });
            if (!o) {
                e.addClass("error").nextAll(".desc").hide();
                if (u) {
                    var a = e.nextAll(".error");
                    a.length || (a = t("<p class='error'></p>").insertAfter(e)),
                    a.text(u).show()
                }
            } else e.removeClass("error").nextAll(".desc").show().end().nextAll(".error").remove();
            return o
        },
		//验证器
        validate: {
            required: function(e, n) {
                return {
                    valid: !!t.trim(e),
                    errorMsg: "请填写这个字段"
                }
            },
            length: function(e, t) {
                t = (t || "0").split(",");
                var n = e.length,
                r = t[0] * 1,
                i = t.length > 1 ? t[1] * 1: null;
                return {
                    valid: !e || n >= r && (!i || n <= i),
                    errorMsg: "这个字段的长度不能" + (r > 0 ? "少于" + r + "位": "") + (i ? "多余" + i + "位": "")
                }
            },
            range: function(e, t) {
                t = (t || "0").split(",");
                var n = t[0] * 1,
                r = t.length > 1 ? t[1] * 1: null;
                return {
                    valid: !e || e >= n && (!r || e <= r),
                    errorMsg: "这个字段的值" + (n > 0 ? "不能小于" + n: "") + (r ? "不能大余" + r: "")
                }
            },
            email: function(e, t) {
                var n = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
                return {
                    valid: !e || n.test(e),
                    errorMsg: "请填写正确的邮箱地址"
                }
            },
            number: function(e, t) {
                return {
                    valid: !e || /^\d+$/.test(e),
                    errorMsg: "请填写数字"
                }
            },
            mobile: function(e, t) {
                return {
                    valid: !e || /^\d{11}$/.test(e),
                    errorMsg: "请填写一个有效的手机号码"
                }
            }
        },
		//弹窗
        popover: function(e, n) {
            if (n == "hide") {
                var r = t(e).data("popover");
                r && (r.remove(), t(e).removeClass("popover-target").data("popover", null), t(document).unbind(".popover"))
            } else {
                var i = t(".popover");
                i.length > 0 && i.each(function(e, n) {
                    mcw.popover(t(n).data("target"), "hide")
                }),
                e = t(e);
                var s = e.offset(),
                o = e.outerWidth(),
                u = e.outerHeight(),
                a = t(window).height(),
                r = t("<div class='popover'>					<div class='popover-content'></div>					<div class='popover-arrow'></div>				</div>");
                r.appendTo("body").find(".popover-content").append(n.content);
                var f = r.outerHeight(),
                l = t(document).scrollTop(),
                c = t(document).scrollLeft(),
                h = r.find(".popover-arrow").width(),
                p = r.find(".popover-arrow").height(),
                d = 15,
                v,
                m;
                a - s.top + l < f + 10 ? (r.addClass("direction-up"), v = s.top + u / 2 + p / 2 + d - f, m = s.left + o + h + 5) : (r.addClass("direction-down"), v = s.top + u / 2 - p / 2 - d, m = s.left + o + h + 5),
                r.css({
                    top: v,
                    left: m
                }),
                t(document).bind("mousedown.popover", 
                function(n) {
                    var i = t(n.target);
                    if (i[0] == e[0] || r.has(i).length) return;
                    mcw.popover(e, "hide")
                }),
                e.addClass("popover-target").data("popover", r),
                r.data("target", e)
            }
        },
		//高亮
        highlight: function(e, t, n) {
            n = n || "transparent",
            e.stop(!0, !0).css({
                backgroundColor: t || "#fffed6"
            }),
            setTimeout(function() {
                e.animate({
                    backgroundColor: n
                },
                {
                    queue: !1,
                    duration: 1e3
                })
            },
            100)
        },
		//滚动加载
        scrollLoad: function(e, n) {
            function o() {
                if (s.offset().top - i.scrollTop() < r) {
                    if (s.hasClass("loading")) return;
                    s.addClass("loading").text("正在加载更多...");
                    var e = n(s);
                    e && e.done(function(e) {
                        e ? (s.removeClass("loading").text("加载更多内容"), o()) : s.removeClass("loading").addClass("over").text("没有更多内容了").unbind("click")
                    })
                }
            }
            var r,
            i = t(window);
            if (e === !1) {
                t(window).unbind(".scrollLoad"),
                i.unbind(".scrollLoad");
                return
            }
            var s = t("#btn-load-more", e);
            if (!s.length) return;
            t(window).unbind(".scrollLoad").bind("resize.scrollLoad", 
            function(e) {
                r = t(window).height()
            }).resize(),
            i.unbind(".scrollLoad").bind("scroll.scrollLoad", 
            function(e) {
                if (s.is(".loading, .over")) return;
                o()
            }).scroll()
        },
		//快捷键转换
        metaKey: function(e) {
            var t = /Mac/.test(navigator.userAgent);
            return t ? e.metaKey: e.ctrlKey
        },
		//播放视频
        playAudio: function(e, n) {
            var r = t("#audio-" + e);
            r.length || (r = t('<audio id="audio-' + e + '">						<source src="' + n + '" type="audio/mpeg" />					</audio>').appendTo("body")),
            r = r.get(0),
            t.browser.chrome && r.load(),
            r.play()
        },
		//解析时间
        prettyDate: function(e, t) {
            var n = moment(e, t),
            r = moment(),
            i = r.diff(n);
            if (i < 0) return "刚刚";
            if (n.diff(moment().add("d", -1).startOf("day")) < 0) return n.format("M月D日");
            if (n.diff(moment().startOf("day")) < 0) return "昨天";
            if (i < 6e4) return "刚刚";
            if (i >= 6e4 && i < 36e5) return Math.round(i / 6e4).toFixed(0) + "分钟前";
            if (i >= 36e5 && i < 864e5) return Math.round(i / 36e5).toFixed(0) + "小时前"
        },
		//本地离线存储
        autosave: function(e) {
            e = e || document;
            var n = t("[data-autosave]", e),
            r = mcw.urlParts(location.href),
            i = [];
            n.each(function(e, n) {
                var n = t(n),
                s = n.data("autosave"),
                o = r.path + s + "/autosave/";
                if (!s) return;
                n.off("keyup.autosave").on("keyup.autosave", 
                function() {
                    var e = t(this).val();
                    localStorage[o] = e
                }),
                localStorage[o] && n.val(localStorage[o]),
                i.push(o)
            }),
            n.closest(".form").off("ajax:success.autosave").on("ajax:success.autosave", 
            function(e) {
                t.each(i, 
                function(e, t) {
                    localStorage[t] = ""
                })
            })
        }
    }
} (jQuery),

//全局URL控制，错误页定位，AJAX内容加载

function(e) {
    var t = {},
    n = {},
    r = null,
    i = {},
    //是否支持pushState和replaceState
    s = window.history && window.history.pushState && window.history.replaceState;
    e(function() {
        function l(t) {
            i && (n[i.url] = e(this).scrollTop())
        }
        function c(url, n) {
            var r = url;
            if (typeof url != "object") {
                //添加sheet-header头部
                var i = o.find(".sheet-active");
                if (i.length) {
                    var s = mcw.urlParts(i.data("url")).href;
                    i.empty().removeClass("sheet-active").attr("data-url", s).attr("data-id", i.attr("id")).removeAttr("id");
                    var u = e("<div class='sheet-header'><a class='link-parent-sheet' data-stack data-stack-replace></a></div>").appendTo(i);
                    u.find(".link-parent-sheet").attr("href", s).attr("data-restore-position", "true").text(i.data("page-name"))
                }
                //添加内容占位
                r = e("<div class='page hidden empty'></div>");
                if (!n) {
                    var a = o.find(".page").length;
                    r.addClass("sheet sheet-active sheet-" + (a || "root")).attr("data-url", url)
                }
                r.appendTo(i.length ? i: o),
                r.removeClass("hidden")
            } else r.addClass("empty").children(".page").remove(),
            r.hasClass("sheet") && r.addClass("sheet-active"),
            r.data("id") && r.attr("id", r.data("id"));
            return r
        }
        function h(n, i, s, u) {
            function renderHtml(r) {
                var u = o.find(".page").index(n),
                a = e(r).attr("data-url", i).removeClass("sheet-root sheet-1 sheet-2 sheet-3 sheet-4").addClass("sheet-" + (u || "root")).addClass("empty");
                n.replaceWith(a);
                var f = a.attr("id");
                return mcw.pages[f] && mcw.pages[f].init(a),
                e(document).trigger("afterstack", [a]),
                a.removeClass("empty"),
                t[i] = {
                    id: f,
                    name: a.data("page-name") + " - Tower",
                    html: e("<div/>").append(a.clone()).html()
                },
                s && s(a),
                mcw.live && mcw.live(),
                a
            }
            function l() {
                i || (i = mcw.urlParts(n.data("url")).href),
                xhr = $.ajax({
                    url: i,
                    type: "get",
                    headers: {
                        "X-PJAX": "true"
                    },
                    data: {
                        pjax: 1
                    },
                    complete: function() {
                        xhr = null
                    },
                    dataType: "html",
                    error: function(e) { ! e || e.status !== 404 && e.status !== 403 ? e && e.status === 502 ? mcw.message({
                            msg: "抱歉，系统繁忙，请稍后刷新页面。"
                        }) : e && e.status === 500 && mcw.message({
                            msg: "抱歉，系统出错了，请稍后刷新页面。"
                        }) : renderHtml(e.responseText),
                        mcw.clearPageCache(i)
                    },
                    success: function(e) {
                        renderHtml(e)
                    }
                })
            }
            if (!n || !n.length) return;
            var a = t[i]; ! u && a && a.html ? (n = f(a.html), n.data("pjax-refresh") === !1 ? mcw.live && mcw.liveHandler() : l()) : (i && n.addClass("loading"), l())
        }
        window.mcw || (mcw = {});
        if (!s) {
            e.extend(mcw, {
                stack: function(e) {
                    location.href = e.url
                },
                clearPageCache: function() {}
            });
            return
        }
        var o = e(".workspace"),
        u = e(document).on("scroll.stack", l);
        if (o.length) {
            var a = mcw.urlParts(location.href).href,
            f = o.find(".page:last").attr("data-url", a);
            t[a] = {
                id: f.attr("id"),
                name: document.title,
                html: e("<div/>").append(f.clone()).html()
            },
            i = {
                id: f.attr("id"),
                name: document.title,
                url: a,
                html: o.html()
            },
            history.replaceState(i, i.name, i.url)
        }
        e.extend(mcw, {
            clearPageCache: function(e) {
                e ? t[e] = undefined: t = {}
            },
            stack: function(s) {
                s = e.extend({
                    url: "",
                    root: !1,
                    replace: !1,
                    bare: !1,
                    restorePosition: !1,
                    parent: null,
                    nocache: !1
                },
                s);
                var a = e.Event("beforestack");
                e(document).trigger(a);
                if (a.result === !1) return;
                r && (r.abort(), r = null),
                u.off("scroll.stack", l),
                mcw.live && mcw.live(!1);
                var f = mcw.urlParts(s.url),
                p = mcw.urlParts(location.href),
                d = o.find(".page:last"),
                v = d.hasClass("loading"),
                m = null;
                d.length && !d.hasClass("empty") && (t[p.href] = {
                    id: d.attr("id"),
                    name: d.data("page-name") + " - Tower",
                    html: e("<div/>").append(d.clone()).html()
                },
                i.html = o.html(), history.replaceState(i, i.name, i.url)),
                f.path == p.path && f.search == p.search ? m = d: s.root ? (o.empty(), s.parent && e("<div class='page sheet sheet-root sheet-active'></div>").attr("data-page-name", s.parent.name).attr("data-url", s.parent.url).appendTo(o)) : s.replace && (o.find(".page").each(function() {
                    var t = e(this),
                    n = mcw.urlParts(t.data("url"));
                    if (n && f.path == n.path) return m = t,
                    t[0] != d[0] && c(t),
                    !1
                }), m || (m = d.empty(), c(m)));
                if (!m || m.length < 1) m = c(f.href, s.bare);
                i = {
                    url: f.href,
                    name: "正在加载...",
                    html: o.html()
                },
                history[v ? "replaceState": "pushState"](i, i.name, i.url),
                document.title = i.name,
                !f.hash && s.restorePosition && n[f.href] !== undefined ? u.scrollTop(n[f.href]) : u.scrollTop(0),
                u.on("scroll.stack", l).scroll(),
                h(m, f.href, 
                function(e) {
                    i = {
                        id: e.attr("id"),
                        url: f.href,
                        name: e.data("page-name") + " - Tower",
                        html: o.html()
                    },
                    history.replaceState(i, i.name, i.url),
                    document.title = i.name,
                    f.hash && setTimeout(function() {
                        mcw.scrollTo(f.hash, {
                            anim: !1
                        })
                    },
                    0),
                    window._gaq && _gaq.push(["_trackPageview"])
                },
                s.nocache)
            }
        }),
        e(document).on("click.stack", "a[data-stack]", 
        function(t) {
            var n = mcw.metaKey(t);
            if (n) return;
            t.preventDefault();
            var r = e(this),
            i = null;
            r.is("[data-parent-name][data-parent-url]") && (i = {
                name: r.data("parent-name"),
                url: r.data("parent-url")
            }),
            mcw.stack({
                url: r.data("url") || r.attr("href"),
                root: r.is("[data-stack-root]"),
                replace: r.is("[data-stack-replace]"),
                bare: r.is("[data-stack-bare]"),
                restorePosition: r.is("[data-restore-position]"),
                nocache: r.is("[data-nocache]"),
                parent: i
            })
        }),
        e(window).on("popstate.stack", 
        function(t) {
            var s = t.originalEvent.state;
            if (!s) return;
            r && (r.abort(), r = null),
            mcw.live && mcw.live(!1),
            e(document).trigger("beforestack"),
            u.off("scroll.stack", l),
            o.html(s.html),
            document.title = s.name,
            i = s;
            var a = o.find(".page:last"),
            f = a.attr("id");
            mcw.pages[f] && mcw.pages[f].init(a),
            a.data("pjax-refresh") === !1 ? mcw.live && mcw.liveHandler() : h(a, null, null, !0),
            n[s.url] !== undefined ? u.scrollTop(n[s.url]) : u.scrollTop(0),
            u.on("scroll.stack", l).scroll()
        })
    })
} (jQuery),

//编辑器支持可拖拽以及进度

function(e) {
    function n(t) {
        function o(i) {
            var s = /(_|\*)(\S+?)(_|\*)\s/g,
            o;
            while ((o = s.exec(i.data)) != null) {
                var u = i.data.substr(0, o.index) + o[2] + i.data.substr(o.index + o[0].length, o.input.length - 1),
                a = n.createTextNode(u);
                e(i).replaceWith(a);
                var f = rangy.createRange(n);
                f.setStart(a, o.index),
                f.setEnd(a, o.index + o[2].length),
                r.setSelection(f),
                t.composer.commands.exec("bold"),
                r.setAfter(r.getSelectedNode().parentNode),
                e(r.getSelectedNode()).closest("b").length && t.composer.commands.exec("bold")
            }
        }
        function u(i) {
            var s = /^\*\s+(\S*?)/g,
            o;
            while ((o = s.exec(i.data)) != null) {
                if (i.previousSibling && !e(i.previousSibling).is("br")) return;
                var u = i.data.substr(0, o.index) + o[1] + i.data.substr(o.index + o[0].length),
                a = rangy.createRange(n);
                a.setStartAfter(i),
                a.setEndAfter(i),
                r.setSelection(a),
                t.composer.commands.exec("insertUnorderedList");
                var f = r.getSelectedNode();
                f.textContent = u;
                var l = e(f).closest("li");
                if (l.length) {
                    var c = n.createTextNode(wysihtml5.INVISIBLE_SPACE);
                    l.append(c),
                    r.selectNode(c)
                } else r.setAfter(f)
            }
        }
        function a(i) {
            var s = /^\d[\.、]\s(\S*?)/g,
            o;
            while ((o = s.exec(i.data)) != null) {
                var u = i.data.substr(0, o.index) + o[1] + i.data.substr(o.index + o[0].length),
                a = rangy.createRange(n);
                a.setStartAfter(i),
                a.setEndAfter(i),
                r.setSelection(a),
                t.composer.commands.exec("insertOrderedList");
                var f = r.getSelectedNode();
                f.textContent = u;
                var l = e(f).closest("li");
                if (l.length) {
                    var c = n.createTextNode(wysihtml5.INVISIBLE_SPACE);
                    l.append(c),
                    r.selectNode(c)
                } else r.setAfter(f)
            }
        }
        var n = t.composer.doc,
        r = t.composer.selection,
        i = rangy.createRange(n);
        i.selectNode(n.body);
        var s = i.getNodes([3]);
        e.each(s, 
        function(e, t) {
            o(t),
            u(t),
            a(t)
        })
    }
    function r(e) {
        var t = e.originalEvent.dataTransfer,
        n = navigator.userAgent.indexOf("AppleWebKit") > -1;
        return t && t.effectAllowed != "none" && (t.files || !n && t.types.contains && t.types.contains("Files"))
    }
    e(function() {
        e("body").on("validate", ".form-editor", 
        function(t, n, r) {
            var i = e(this).find(".editor:first"),
            s = i.find(".attachment:visible"),
            o = e(t.currentTarget),
            u = {
                valid: !0
            };
            return /^((&nbsp;)*\s*(<br>)*)*$/.test(n) && !e.trim(o.find("input[type=text]").val()) && !s.length ? (i.addClass("error"), u.valid = !1) : n.length > 5e3 ? (i.addClass("error"), u.valid = !1, mcw.message({
                msg: "内容最长5000个字符"
            })) : i.removeClass("error"),
            s.each(function() {
                if (e(this).hasClass("uploading")) return i.addClass("error"),
                u.valid = !1,
                !1
            }),
            u
        }).on("ajax:beforeSend", ".form-editor", 
        function(t, n, r) {
            var i = e(".member-list input:checked").map(function() {
                return e(this).val()
            }).get();
            r.data += "&cc_guids=" + i.join(",");
            var s = e(this).find(".editor:first"),
            o = s.find(".attachment[fileid]:visible").map(function() {
                return e(this).is("[attachId]") ? e(this).attr("attachId") : null
            }).get(),
            u = s.find(".attachment:hidden:not([fileid])").map(function() {
                return e(this).is("[attachId]") ? e(this).attr("attachId") : null
            }).get(),
            a = s.find(".attachment:visible").map(function() {
                return e(this).is("[attachId]") ? e(this).attr("attachId") : null
            }).get();
            r.data += "&attach_guids=" + o.join(",") + "&delete_attach_guids=" + u.join(",") + "&attach_order=" + a.join(",")
        }).on("click", ".link-select-all", 
        function(t) {
            t.preventDefault(),
            e(t.currentTarget).parents(".notify:first").find(".member-list input:checkbox").attr("checked", "checked")
        }).on("click", ".link-select-none", 
        function(t) {
            t.preventDefault(),
            e(t.currentTarget).parents(".notify:first").find(".member-list input:checkbox").removeAttr("checked")
        }).on("click", ".link-change-notify", 
        function(t) {
            t.preventDefault(),
            e(t.currentTarget).parent().hide().parents(".notify:first").find(".select-all").show().end().find(".form-field").show().end().find(".receiver").hide()
        })
    }),
    window.mcw || (mcw = {});
    var t = {
        attachment: "<div class='attachment'>				<img src='/assets/file_icons/file_extension_others-794dbedf3ee0e0e7ea0a61d225ff67f4.png'/>				<span class='name'></span>				<span class='size'></span>				<div class='progress-bar'><div><span></span></div></div>				<span class='percent'>0%</span>				<a href='javascript:;' class='link-cancel' title='Cancel'>Cancel</a>			</div>",
        toolbar: '<div class="editor-toolbar">				<a class="toolbar-button toolbar-button-em" data-wysihtml5-command="formatInline" data-wysihtml5-command-value="b" href="javascript:;" title="加粗文字">加粗文字</a>				<a class="toolbar-button toolbar-button-ul" data-wysihtml5-command="insertUnorderedList" href="javascript:;" title="无序列表">无序列表</a>				<a class="toolbar-button toolbar-button-ol" data-wysihtml5-command="insertOrderedList" href="javascript:;" title="有序列表">有序列表</a>			</div>'
    };
    e.extend(mcw, {
        editor: function(n, i) {
            function d(e) {
                var t = o.parents("form:first").find("button[type=submit]");
                e === "normal" && t.prop("disabled") ? t.prop("disabled", !1).text(t.data("originText") || t.data("ujs:enable-with")).removeData("originText") : e === "uploading" && !t.prop("disabled") && t.prop("disabled", !0).data("originText", t.text()).text("正在上传附件...")
            }
            i = e.extend({},
            i, {
                upload: !0,
                toolbar: !0
            });
            var s = e(n),
            o,
            u;
            s.parent().is(".editor") ? o = s.parent() : o = s.wrap("<div class='editor' />").parent(),
            mcw.autosave(o.closest(".form-editor")),
            i.toolbar && (u = e(t.toolbar).insertAfter(s));
            var a = (new wysihtml5.Editor(s[0], {
                toolbar: u ? u[0] : undefined,
                style: !1,
                parserRules: wysihtml5ParserRules,
                stylesheets: ["/assets/editor-774343d3556ec6d051d1447a894bbc3d.css"]
            })).on("load", 
            function() {
                if (!a || !a.composer) return;
                e(a.composer.doc).on("dragover", 
                function(t) {
                    r(t) && e(document).trigger("dragover_if.editor")
                }),
                e(a.composer.doc).bind("drop dragenter dragover dragleave", 
                function(e) {
                    return e.preventDefault(),
                    !1
                }),
                e(a.composer.doc.body).bind("keydown", 
                function(e) {
                    var t = mcw.metaKey(e);
                    if (e.which == 13 && t) return s.closest(".form").find("button:submit").click(),
                    !1
                });
                var t = s.attr("tabindex");
                t && e(a.composer.iframe).attr("tabindex", t)
            }).on("focus:composer", 
            function() {
                a && a.composer && (e(a.composer.iframe).closest(".editor").addClass("focus"), a.heightInterval = setInterval(e.proxy(function() {
                    a && a.composer ? e(a.composer.iframe).css({
                        minHeight: Math.max(90, e(a.composer.element).outerHeight() + 10)
                    }) : a && (clearInterval(a.heightInterval), a.heightInterval = null)
                },
                this), 300), o.removeClass("error"))
            }).on("blur", 
            function() {}).on("blur:composer", 
            function() {
                a && a.composer && e(a.composer.iframe).closest(".editor").removeClass("focus"),
                a && a.heightInterval && (clearInterval(a.heightInterval), a.heightInterval = null)
            });
            e(a.textareaElement).is("[data-autosave]") && a.on("change:composer", 
            function() {
                if (a) {
                    var t = mcw.urlParts(location.href),
                    n = e(a.textareaElement).data("autosave"),
                    r = a.getValue(),
                    i = t.path + n + "/autosave/";
                    if (!n) return;
                    localStorage[i] = r
                }
            }),
            o.data("editor", a);
            if (mcw.upload && i.upload) {
                var f = o.find(".editor-attachments"),
                l = o.find(".add-attachment");
                l.length < 1 && (l = e('<div class="add-attachment">添加附件</div>')),
                o.after('<p class="upload-limit-desc">单个附件支持最大50MB</p>'),
                l.insertAfter(a.currentView.iframe),
                f.length < 1 && (f = e("<div class='editor-attachments'></div>").appendTo(o));
                var c = mcw.upload(l, {
                    action: "/upload/attachments",
                    beforeUpload: function(n) {
                        var r = e(t.attachment).attr({
                            fileid: n.id
                        }).prependTo(f);
                        mcw.loadImage(n.obj, 
                        function(e) {
                            if (!e) {
                                var t = "/assets/file_icons/",
                                i = t + "file_extension_" + n.extension + ".png";
                                mcw.loadImage(i, 
                                function(e) {
                                    e ? r.find("img").attr("src", e.src) : r.find("img").attr("src", t + "file_extension_others.png")
                                })
                            } else r.find("img").attr({
                                src: e.src,
                                "data-origin-src": e.src,
                                "data-origin-size": e.width + "," + e.height,
                                "data-origin-name": n.name
                            }).css("cursor", "pointer")
                        });
                        if (window.File && window.FileList) {
                            var i = 0;
                            n.size >= 1048576 ? i = (n.size / 1048576).toFixed(1) + "M": i = (n.size / 1024).toFixed(0) + "K"
                        } else r.find(".progress-bar").remove().end().find(".percent").text("正在上传...").addClass("ie");
                        r.addClass("uploading"),
                        r.find(".name").text(n.name),
                        r.find(".size").text(i),
                        r.find(".link-cancel").text("取消上传").attr("title", "取消上传"),
                        d("uploading"),
                        l.addClass("active")
                    },
                    onProgress: function(e, t, n) {
                        var r = f.find(".attachment[fileid=" + e.id + "]"),
                        i = (t / n * 100).toFixed(0) + "%";
                        r.find(".progress-bar span").width(i),
                        r.find(".percent").text(i)
                    },
                    onValidate: function(e, t) {
                        return e.size && e.size / 1048576 > 50 ? (mcw.message({
                            msg: '附件 <em style="color: #ee6500;">' + e.name + "</em> 大小超过50MB, 无法完成上传",
                            width: 500
                        }), !1) : !0
                    },
                    onSuccess: function(e, t) {
                        var n = f.find(".attachment[fileid=" + e.id + "]");
                        n.find(".progress-bar, .percent").remove(),
                        n.removeClass("uploading").attr("attachid", t.attach).find(".link-cancel").text("移除附件").attr("title", "移除附件"),
                        mcw.loadImage(t.file_path, 
                        function(e) {
                            e && n.find("img").attr({
                                src: e.src,
                                "data-origin-src": e.src,
                                "data-origin-size": e.width + "," + e.height
                            })
                        })
                    },
                    onCancel: function(e) {},
                    onError: function(t, n) {
                        var r = e.parseJSON(n.responseText);
                        mcw.message({
                            msg: r.msg
                        }),
                        f.find(".attachment.uploading .link-cancel").click(),
                        d("normal")
                    },
                    onComplete: function(e, t) {
                        c.getInProgress() === 0 && d("normal")
                    }
                }),
                h,
                p = e('<div class="droparea"><span>拖动文件到这里，添加附件</span></div>').appendTo(o);
                p.on("dragover", 
                function(e) {
                    if (!r(e)) return;
                    p.addClass("droparea-active");
                    var t = e.originalEvent.dataTransfer.effectAllowed;
                    /^(move|linkMove)$/.test(t) ? e.originalEvent.dataTransfer.dropEffect = "move": e.originalEvent.dataTransfer.dropEffect = "copy",
                    e.stopPropagation(),
                    e.preventDefault(),
                    clearTimeout(h),
                    h = setTimeout(function() {
                        p.hide()
                    },
                    500)
                }).on("dragenter", 
                function(e) {
                    if (!r(e)) return;
                    p.addClass("droparea-active")
                }).on("dragleave", 
                function(t) {
                    if (!r(t)) return;
                    var n = e(document.elementFromPoint(t.originalEvent.clientX, t.originalEvent.clientY));
                    if (n.is(".droparea") || n.parent(".droparea").length) return;
                    p.removeClass("droparea-active")
                }).on("drop", 
                function(t) {
                    if (!r(t)) return;
                    var n;
                    if (!t.originalEvent.dataTransfer.files || !t.originalEvent.dataTransfer.files.length) return;
                    files = t.originalEvent.dataTransfer.files,
                    files && e.each(files, 
                    function(e, t) {
                        c.uploadFile(t)
                    })
                }),
                a.on("paste:composer", e.proxy(function(t) {
                    if (!t || !t.dataTransfer) {
                        var n = e("img", a.composer.element),
                        r = n.map(function(t, n) {
                            return e(n).attr("src")
                        }).get();
                        n.remove(),
                        e.each(r, 
                        function(e, t) {
                            blob = window.dataURLtoBlob && window.dataURLtoBlob(t),
                            blob.name = "屏幕截图 " + moment().format("YYYY-MM-DD HH:mm:ss") + ".png",
                            c.uploadFile(blob)
                        })
                    } else {
                        var i;
                        if (t.dataTransfer.files && t.dataTransfer.files.length) t.originalEvent.stopPropagation(),
                        t.originalEvent.preventDefault(),
                        i = t.dataTransfer.files[0];
                        else {
                            if (! (t.dataTransfer.items && t.dataTransfer.items.length && t.dataTransfer.items[0].type.indexOf("image") > -1)) {
                                if (t.dataTransfer.types && (e.inArray("image/png", t.dataTransfer.types) > -1 || e.inArray("image/tiff", t.dataTransfer.types) > -1)) return t.originalEvent.preventDefault(),
                                !1;
                                return
                            }
                            t.originalEvent.stopPropagation(),
                            t.originalEvent.preventDefault(),
                            i = t.dataTransfer.items[0]
                        }
                        i && (i.getAsFile && (i = i.getAsFile()), i.name || (i.name = "屏幕截图 " + moment().format("YYYY-MM-DD HH:mm:ss") + ".png"), c.uploadFile(i))
                    }
                },
                this)),
                e(document).on("dragenter.editor", 
                function(e) {
                    if (!r(e)) return;
                    p.show()
                }).on("dragover.editor", 
                function(e) {
                    if (!r(e)) return;
                    e.originalEvent.dataTransfer.dropEffect = "none",
                    e.preventDefault(),
                    clearTimeout(h),
                    h = setTimeout(function() {
                        p.hide()
                    },
                    500)
                }).on("drop.editor", 
                function(e) {
                    p.hide(),
                    e.preventDefault()
                }).on("click.editor", ".editor-attachments .link-cancel", 
                function(t) {
                    t.preventDefault();
                    var n = e(t.currentTarget).parents(".attachment:first"),
                    r = n.siblings(".attachment:visible"),
                    i = n.attr("fileid");
                    i && n.hasClass("uploading") && c.cancel(i),
                    n.hide().removeClass("uploading"),
                    r.length || l.removeClass("active")
                }).on("dragover_if.editor", 
                function(e) {
                    p.show()
                }),
                f.sortable({
                    axis: "y",
                    item: ".attachment",
                    cursor: "move",
                    helper: "clone",
                    tolerance: "pointer",
                    placeholder: "editor-attach-placeholder",
                    containment: "parent"
                })
            }
            return e.extend(a, {
                destroyEditor: function() {
                    var t = e(a.textarea.element).closest(".form").off(".editor");
                    t.data("submitEvent") && (t.data("submitEvent").stop(), e.removeData(t, "submitEvent")),
                    t.data("resetEvent") && (t.data("resetEvent").stop(), e.removeData(t, "resetEvent")),
                    clearInterval(a.heightInterval),
                    a = null,
                    o.find(".editor-attachments .link-cancel").click(),
                    o.next(".upload-limit-desc").remove(),
                    d("normal");
                    var n = s.nextAll("iframe.wysihtml5-sandbox").remove();
                    s.nextAll("input[name='_wysihtml5_mode'], .editor-attachments, .add-attachment, .editor-toolbar").remove(),
                    e("body").removeClass("wysihtml5-supported"),
                    e(document).off(".editor"),
                    p && p.remove(),
                    s.unwrap().val("")
                }
            }),
            o.data("editor", a),
            a
        }
    })
} (jQuery),

//日期选择插件

function(e) {
    var t = {
        inline: !1,
        showPrevNext: !0,
        disableToday: !1,
        allowOld: !0,
        format: "YYYY-MM-DD"
    },
    n = function(n, r) {
        this.el = e(n);
        var i = e.extend({},
        t, r);
        this.el.data("settings", i);
        var s = this.el.val();
        s && (this.selectedDate = moment(s, i.format)),
        i.inline ? this.show() : (this.el.focus(e.proxy(function(e) {
            this.show()
        },
        this)).focus(), e(document).bind("click.datepicker", e.proxy(function(e) {
            this.hide()
        },
        this)))
    };
    e.extend(n.prototype, {
        show: function() {
            this.update()
        },
        hide: function() {
            this.cal && (this.cal.remove(), this.cal = null, e(document).unbind(".datepicker"))
        },
        setStartDate: function(e) {
            this.el.data("settings").startDate = e,
            this.cal && this.update()
        },
        setEndDate: function(e) {
            this.el.data("settings").endDate = e,
            this.cal && this.update()
        },
        setSelectedDate: function(e) {
            if (!e) this.selectedDate = null,
            this.el.val("");
            else {
                this.selectedDate = moment(e);
                var t = this.el.data("settings");
                this.el.val(this.selectedDate.format(t.format))
            }
            this.cal && this.update()
        },
        update: function() {
            var t = this.el,
            n = t.data("settings"),
            r = t.data("theDate") || this.selectedDate || moment().startOf("day"),
            i = r.clone().startOf("month"),
            s = r.clone().endOf("month"),
            o = r.clone().add("months", -1).endOf("month"),
            u = ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"];
            t.data("theDate", r);
            var a = "";
            for (var f = 0, l = 0; f < 6; f++) {
                var c = "";
                for (var h = 0; h < 7; h++, l++) {
                    var p = o.date() - o.day() + l + 1,
                    d = p - o.date(),
                    v = h == 6 ? "sun": h == 5 ? "sat": "day";
                    if (d >= 1 && d <= s.date()) {
                        var m = moment().startOf("day"),
                        g = r.clone().date(d);
                        v += m.diff(g) == 0 ? " today": "",
                        n.allowOld || (v += g.diff(m) < 0 ? "disabled": ""),
                        this.selectedDate && (v += g.diff(this.selectedDate) == 0 ? " selected": "")
                    } else {
                        if (d > s.date() && h == 0) break;
                        v = "disabled",
                        d = d <= 0 ? p: p - s.date() - o.date()
                    }
                    c += "<td class='datepicker-day'><a href='javascript:;' class='" + v + "'>" + d + "</div></td>"
                }
                c && (a += "<tr class='days'>" + c + "</tr>")
            }
            var y = n.allowOld,
            b = !0;
            n.showPrevNext || (y = b = !1);
            var w = r.year() + "年" + u[r.month()],
            E = "<table><tr><td class='datepicker-prev'>" + (y ? "<a href='javascript:;'>Prev</a>": "") + "</td>" + "<td class='datepicker-title' colspan='5'>" + w + "</td>" + "<td class='datepicker-next'>" + (b ? "<a href='javascript:;'>Next</a>": "") + "</td>" + "</tr>" + "<tr class='datepicker-dow'>" + "<td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td><td>日</td>" + "</tr>" + a + "</table>";
            if (!this.cal) {
                this.cal = e("<div class='datepicker'></div>").insertAfter(t);
                if (!n.inline) {
                    var S = t.offset();
                    this.cal.css({
                        position: "absolute",
                        "z-index": n.zIndex || 100,
                        left: S.left,
                        top: S.top + t.outerHeight(!0)
                    })
                }
                this.cal.on("click", 
                function(e) {
                    return ! 1
                }).on("click", ".datepicker-prev a", e.proxy(function(t) {
                    var n = e(t.currentTarget),
                    r = this.el.data("theDate"),
                    i = r.clone().add("months", -1);
                    this.el.data("theDate", i),
                    this.update()
                },
                this)).on("click", ".datepicker-next a", e.proxy(function(t) {
                    var n = e(t.currentTarget),
                    r = this.el.data("theDate"),
                    i = r.clone().add("months", 1);
                    this.el.data("theDate", i),
                    this.update()
                },
                this)).on("click", ".datepicker-day a", e.proxy(function(t) {
                    t.preventDefault();
                    var n = e(t.currentTarget);
                    if (n.hasClass("disabled")) return;
                    var r = n.text(),
                    i = this.el.data("settings"),
                    s = this.el.data("theDate"),
                    o = s.clone().date(r);
                    this.el.data("theDate", o),
                    this.el.val(o.format(i.format)),
                    this.selectedDate = o,
                    this.cal.find(".datepicker-day a.selected").removeClass("selected"),
                    n.addClass("selected"),
                    i.inline || this.hide(),
                    i.onSelect && i.onSelect(o)
                },
                this))
            }
            this.cal.html(E)
        }
    }),
    window.mcw || (mcw = {}),
    e.extend(mcw, {
        datepicker: function(t, r) {
            return new n(e(t), r)
        }
    })
} (jQuery),

//轮询状态更新

function(e) {
    function n(t, n) {
        var r = e(t).data("sort") * 1,
        i = e(n).data("sort") * 1;
        return r - i
    }
    function r(t, n) {
        var r = e(t).data("sort") * 1,
        i = e(n).data("sort") * 1;
        return i - r
    }
    e.extend(window.mcw, {
        live: function(e) {
            if (e === !1) {
                clearInterval(mcw.liveInterval),
                mcw.liveInterval = null,
                mcw.liveRequest && (mcw.liveRequest.abort(), mcw.liveRequest = null);
                return
            }
            mcw.live(!1);
            var t = mcw.urlParts(location.href).path;
            mcw.liveInterval = setInterval(mcw.liveHandler, 1e4)
        },
        liveHandler: function() {
            var n = e(".workspace .page:last");
            if (!n.length) return;
            var r = mcw.urlParts(location.href),
            i = n.data("since");
            mcw.liveRequest = e.ajax({
                url: r.path + "live/" + r.search,
                type: "get",
                data: {
                    since: i,
                    conn_guid: e("#conn-guid").val()
                },
                success: function(n) {
                    var r = e(".workspace .page:last"),
                    i = r.attr("id");
                    r.attr("data-since", n.timestamp).data("since", n.timestamp);
                    if (i && mcw.pages[i] && mcw.pages[i].update && mcw.pages[i].update(n) === !1) return;
                    e.each(t, 
                    function(e, t) {
                        t(n)
                    })
                },
                error: function(t, n, i) {
                    if (n === "abort") return;
                    mcw.clearPageCache(r.href);
                    var s = e.parseJSON(t.responseText);
                    console && console.error && console.error(s.msg)
                }
            })
        }
    });
    var t = {
        unread: function(t) {
            t.unread !== undefined && e("#notification-count").toggleClass("unread", t.unread > 0).text(t.unread)
        },
        d18n: function(t) {
            if (t.d18n && mcw.d18n.support() && mcw.d18n.permitted() && e("#d18n-enabled").val() === "true") {
                var n = e.now(),
                r = localStorage.last_d18n_req * 1;
                if (r && n - r < 9900) return;
                localStorage.last_d18n_req = n,
                e.each(t.d18n, 
                function(e, t) {
                    mcw.d18n.show(t)
                })
            }
        },
        unread_notis: function(t) {
            var n = e(".noti-pop-list");
            if (!n.length) return;
            t.unread_notis ? (n.html(t.unread_notis).show(), e(".noti-pop-empty").hide(), mcw.adjustDate(n)) : (n.html("").hide(), e(".noti-pop-empty").show())
        },
        topics: function(t) {
            var n = e(".messages");
            if (!n.length || !t.topics) return;
            var r = [],
            i = !1;
            t.topics.deleted && t.topics.deleted.length && (e.each(t.topics.deleted, 
            function(t, r) {
                n.find(".message[data-guid=" + r + "]").fadeOut(function() {
                    e(this).remove()
                })
            }), e(".init.init-discussion").hide()),
            t.topics.created && t.topics.created.length && (e.each(t.topics.created, 
            function(t, i) {
                var s = e(i),
                o = s.data("guid");
                n.find("[data-guid=" + o + "]").remove(),
                n.prepend(s),
                r.push(s),
                mcw.adjustDate(s)
            }), i = !0),
            t.topics.updated && t.topics.updated.length && (e.each(t.topics.updated, 
            function(t, i) {
                var s = e(i),
                o = s.data("guid");
                n.find("[data-guid=" + o + "]").remove(),
                n.prepend(s),
                r.push(s),
                mcw.adjustDate(s)
            }), i = !0);
            if (i) {
                var s = n.find(".message"),
                o = "YYYY-MM-DD HH:mm:ss Z";
                s.sort(function(t, n) {
                    var r = moment(e(t).data("last-comment-at"), o),
                    i = moment(e(n).data("last-comment-at"), o);
                    return i.diff(r)
                }),
                n.prepend(s)
            }
            var u = e(".workspace .page:last");
            u.is("#page-project") && (n.find(".message:gt(2)").hide(), n.find(".message:lt(3)").show());
            if (t.topics.count) {
                var a = e(".link-more-topics");
                a.length && a.text(a.text().replace(/\d+/, t.topics.count))
            }
            e(r).each(function() {
                mcw.highlight(e(this))
            })
        },
        todolists: function(t) {
            var n = e(".todolists");
            if (!n.length || !t.todolists) return;
            var i = [],
            s = !1;
            t.todolists.created && t.todolists.created.length && (e.each(t.todolists.created, 
            function(t, r) {
                var s = e(r.html),
                o = n.find(".todolist[data-guid=" + s.data("guid") + "]");
                o.length ? o.replaceWith(s) : n.append(s),
                i.push(s.find(".title"))
            }), e(".init-todo-empty, .init-todo-completed").remove(), s = !0),
            t.todolists.deleted && t.todolists.deleted.length && e.each(t.todolists.deleted, 
            function(t, r) {
                n.find(".todolist[data-guid=" + r + "]").fadeOut(function() {
                    e(this).remove()
                })
            }),
            t.todolists.updated && t.todolists.updated.length && e.each(t.todolists.updated, 
            function(e, t) {
                var r = n.find("[data-guid=" + t.guid + "]");
                t.name && r.find(".title h4 a").text(t.name),
                t.position && (r.data("sort", t.position), s = !0),
                i.push(r.find(".title h4 a"))
            });
            if (s) {
                var o = n.children(".todolist");
                o.sort(r),
                n.append(o)
            }
        },
        todos: function(t) {
            if (!t.todos) return;
            var r = [],
            i = [];
            t.todos.created && t.todos.created.length && (e.each(t.todos.created, 
            function(t, n) {
                if (!n.list) return;
                var s = e(n.html),
                o = s.data("guid"),
                u = e(".todolist[data-guid=" + n.list + "]"),
                a = u.find(".todo[data-guid=" + o + "]"),
                f = s.hasClass("completed");
                a.length && a.remove(),
                mcw.setTodoFilter(),
                u.find(f ? ".todos-completed": ".todos-uncompleted").append(s),
                r.push(s),
                i.push(u[0]),
                mcw.adjustTodo(s),
                mcw.adjustDate(s)
            }), e(".init-todo-empty, .init-todo-completed").remove()),
            t.todos.deleted && t.todos.deleted.length && e.each(t.todos.deleted, 
            function(t, n) {
                e(".todo[data-guid=" + n + "]").fadeOut(function() {
                    e(this).remove()
                })
            }),
            t.todos.updated && t.todos.updated.length && e.each(t.todos.updated, 
            function(t, n) {
                var s = e(n.html),
                o = s.data("guid"),
                u = e(".todo[data-guid=" + o + "]"),
                a = s.hasClass("completed"),
                f;
                n.list ? f = e(".todolist[data-guid=" + n.list + "]") : f = u.closest(".todolist"),
                a ? u.fadeOut(function() {
                    f.find(".todos-completed").prepend(s),
                    mcw.adjustDate(s),
                    mcw.adjustTodo(s)
                }) : (u.remove(), f.find(".todos-uncompleted").append(s), mcw.adjustDate(s), mcw.adjustTodo(s)),
                mcw.setTodoFilter();
                if (!f.length) return;
                n.position_changed || r.push(s),
                i.push(f[0])
            }),
            e.each(e.unique(i), 
            function(t, r) {
                var i = e(r).find(".todos-uncompleted"),
                s = e(r).find(".todos-completed"),
                o = i.children(".todo");
                completedEls = s.children(".todo"),
                o.sort(n),
                completedEls.sort(n),
                i.append(o),
                s.append(completedEls)
            }),
            e(r).each(function() {
                mcw.highlight(e(this))
            })
        },
        files: function(t) {
            var n = e(".file-list:first");
            if (!n.length || !t.files) return;
            var r = [];
            t.files.created && t.files.created.length && (e.each(t.files.created, 
            function(t, i) {
                var s = e(i);
                n.prepend(s).closest(".day").show(),
                r.push(s)
            }), e(".init.init-file").remove()),
            t.files.deleted && t.files.deleted.length && e.each(t.files.deleted, 
            function(t, n) {
                e(".file[data-guid=" + n + "]").fadeOut(function() {
                    var t = e(this).closest(".file-list");
                    e(this).remove(),
                    t.find(".file").length || t.closest(".day").hide()
                })
            }),
            t.files.updated && t.files.updated.length && e.each(t.files.updated, 
            function(t, i) {
                var s = e(i),
                o = s.data("guid"),
                u = e(".file[data-guid=" + o + "]");
                u.length ? u.replaceWith(s) : n.prepend(s),
                r.push(s)
            });
            var i = e(".workspace .page:last");
            i.is("#page-project") && (n.find(".file:gt(4)").hide(), n.find(".file:lt(5)").show());
            if (t.files.count) {
                var s = e(".link-more-files");
                s.length && s.text(s.text().replace(/\d+/, t.files.count))
            }
        },
        folders: function(t) {
            var n = e(".folders");
            if (!n.length || !t.dirs) return;
            var r = [];
            t.dirs.created && t.dirs.created.length && e.each(t.dirs.created, 
            function(t, i) {
                var s = e(i);
                n.append(s),
                r.push(s)
            }),
            t.dirs.deleted && t.dirs.deleted.length && e.each(t.dirs.deleted, 
            function(t, r) {
                n.find(".link-folder[data-guid=" + r + "]").fadeOut(function() {
                    e(this).remove()
                })
            }),
            t.dirs.updated && t.dirs.updated.length && e.each(t.dirs.updated, 
            function(t, i) {
                var s = e(i),
                o = s.data("guid"),
                u = n.find(".link-folder[data-guid=" + o + "]");
                u.length ? u.replaceWith(s) : n.append(s),
                r.push(s)
            })
        },
        comments: function(t) {
            var n = e(".comments");
            if (!n.length || !t.comments) return;
            var r = [];
            t.comments.created && t.comments.created.length && e.each(t.comments.created, 
            function(t, i) {
                var s = e(i);
                n.find(".comment-form").before(s),
                r.push(s)
            }),
            t.comments.deleted && t.comments.deleted.length && e.each(t.comments.deleted, 
            function(t, r) {
                n.find("#" + r).fadeOut(function() {
                    e(this).remove()
                })
            }),
            t.comments.updated && t.comments.updated.length && e.each(t.comments.updated, 
            function(t, i) {
                var s = e(i),
                o = s.attr("id"),
                u = n.find("#" + o);
                u.length ? u.replaceWith(s) : n.append(s),
                r.push(s)
            }),
            e(r).each(function() {
                mcw.highlight(e(this))
            })
        }
    }
} (jQuery),

//问题反馈，通知，返回顶部 作为全局加载

function(e) {
    e(function() {
        mcw.preloadImages(["/assets/blank-3dbe121a376a181f0fe840fb1daeeb51.gif", "/assets/loading-b82a3823017fd8cdd7a595e38a196189.gif", "/assets/loading-upload-4acb931056ec71d1ad42f71604910d02.gif", "/assets/icon-enter-key-85ea1f3d6deb90d9a48d4cdc5e34298a.png", "/assets/back-to-top-aa485503b416e67b699c82ee4f7638d0.png", "/assets/tiny-loading-e8bd9af828c29751e76f3d73d4f9e005.gif", "/assets/todo-actions-icon-d145055acdde425ecab942a80aaa9bb4.png", "/assets/todo-actions-icon-today-a8bd827d9d61e3a2d8d06303e631d79c.png"]),
        e(document).on("click", "#link-feedback", mcw.feedbackClick).on("click", "*[data-origin-src]", 
        function(t) {
            var n = e(this),
            r = mcw.metaKey(t);
            r ? window.open(n.attr("data-origin-src")) : mcw.viewImage(n)
        }).on("mouseenter", "*[tooltip]", 
        function(t) {
            var n = e(t.currentTarget),
            r = n.attr("tooltip");
            mcw.tooltip(n, r)
        }).on("mouseleave", "*[tooltip]", 
        function(t) {
            var n = e(t.currentTarget);
            mcw.tooltip(n, "hide")
        }).on("beforestack", 
        function(t) {
            e("*[tooltip]").trigger("mouseleave");
            var n = e(".popover-target");
            n.each(function() {
                mcw.popover(e(this), "hide")
            }),
            e(document).trigger("mousedown.notipop");
            var r = !0;
            e(".editor").each(function(t, n) {
                var i = e(n).closest(".form");
                if (i.find(".attachment.uploading:visible").length && !window.confirm("有文件正在上传中，离开当前页将会自动放弃上传，确定要离开？")) {
                    r = !1;
                    return
                }
                i.find(".btn-cancel-update-comment, .btn-cancel-create-comment, #link-cancel-post").click()
            });
            if (!r) return r;
            mcw.scrollLoad(!1),
            e(".header .nav li.active").removeClass("active")
        }).on("afterstack", 
        function(e, t) {
            mcw.adjustDate(t),
            mcw.adjustPermission(t)
        }).on("click", ".noti-pop .noti-pop-list .notice .link", 
        function(t) {
            var n = e(this).closest(".notice").data("notification-guid");
            mcw.readNotification(n)
        }).on("click", ".back-to-top", 
        function(e) {
            e.preventDefault(),
            mcw.scrollTo("body")
        }),
        function() {
            var t = 0,
            n = null,
            r = e(document);
            e(window).bind("resize.backTop", 
            function(n) {
                t = e(this).height()
            }).resize(),
            r.bind("scroll.backTop", 
            function(i) {
                r.scrollTop() > t * 1.5 ? n || (n = e('<a class="back-to-top" href="#" title="返回顶部">返回顶部</a>').appendTo(".page:last")) : n && (n.remove(), n = null)
            })
        } (),
        e("#notification-count").on("mousedown", 
        function() {
            var t = e(".noti-pop");
            return t.hasClass("on") ? e(document).trigger("mousedown.notipop") : (t.addClass("on"), e(document).unbind(".notipop").bind("mousedown.notipop", 
            function(n) {
                var r = e(n.target);
                r.closest(".noti-pop").length || (t.removeClass("on"), e(document).unbind(".notipop"))
            })),
            !1
        }),
        e("#noti-mark-read").click(function(t) {
            t.preventDefault(),
            e("#notification-count").text(0).removeClass("unread"),
            e(".noti-pop-list").empty().hide(),
            e(".noti-pop-empty").show(),
            e(document).trigger("mousedown.notipop"),
            e.ajax({
                url: "/notifications/read_all/"
            })
        }),
        e(".search-wrap").on("click", 
        function(e) {
            return ! 1
        }).on("click", ".link-search", 
        function(t) {
            var n = e(t.currentTarget).closest(".search-wrap"),
            r = e(document),
            i = e("#form-search");
            if (n.hasClass("active")) return;
            return n.addClass("active").find("#txt-search").focus(),
            r.one("click.search", 
            function(e) {
                n.removeClass("active").find("#txt-search").val(""),
                r.unbind("keyup.search")
            }).bind("keyup.search", 
            function(e) {
                e.keyCode == 27 && (e.preventDefault(), r.trigger("click.search"))
            }),
            !1
        }),
        e("#txt-search").bind("keyup DOMAutoComplete", 
        function() {
            e.trim(e(this).val()).length ? e(this).addClass("enter") : e(this).removeClass("enter")
        }).on("keydown", 
        function(t) {
            var n = e(this);
            if (t.which == 13) {
                var r = e.trim(n.val());
                return r ? (e("#page-search-result").empty().addClass("loading"), mcw.stack({
                    url: e("#form-search").attr("action") + "?keyword=" + encodeURIComponent(r),
                    root: !0
                }), n.val(r).get(0).select()) : n.val(""),
                !1
            }
        }),
        mcw.me = {
            guid: e("#member-guid").val(),
            avatar: e("#member-avatar").val(),
            admin: e("#member-admin").length > 0 ? !0: !1,
            owner: e("#member-owner").length > 0 ? !0: !1
        };
        var t = e(".workspace .page:last"),
        n = t.attr("id");
        n && mcw.pages[n] && mcw.pages[n].init(t),
        mcw.me.guid && mcw.live(),
        mcw.me.avatar && mcw.preloadImages([mcw.me.avatar]),
        mcw.adjustDate(t),
        mcw.adjustPermission(t)
    }),
    e.extend(window.mcw, {
        pages: {},
        feedbackClick: function(e) {
            e.preventDefault();
            var t = mcw.dialog({
                el: mcw.template("tpl-feedback")
            });
            t.find("#txt-feedback").focus(),
            t.find("#link-cancel-feedback").click(function(e) {
                e.preventDefault(),
                mcw.dialog("hide")
            }),
            t.find("form.form-feedback").on("ajax:success", 
            function(e) {
                mcw.message({
                    msg: "感谢您的反馈，我们会尽快处理。"
                })
            })
        },
        d18n: {
            support: function() {
                return e.browser.safari ? !!window.Notification: e.browser.chrome ? !!window.webkitNotifications: !1
            },
            permitted: function() {
                if (!mcw.d18n.support()) return ! 1;
                if (e.browser.safari) return Notification.permissionLevel() === "granted";
                if (e.browser.chrome) return webkitNotifications.checkPermission() == 0
            },
            requestPermission: function(t) {
                if (!mcw.d18n.support()) return;
                t = t || 
                function() {},
                e.browser.safari ? Notification.requestPermission(t) : e.browser.chrome && webkitNotifications.requestPermission(t)
            },
            show: function(t) {
                if (!mcw.d18n.support()) return;
                var n = null;
                e.browser.safari ? n = new Notification(t.title, t.content) : e.browser.chrome && (n = webkitNotifications.createNotification("/assets/icon-tower-479344ffcf99c7852fa40955302e15ac.png", t.title, t.content)),
                n.onclick = function() {
                    mcw.stack({
                        url: t.url,
                        root: !0,
                        parent: {
                            name: "全部通知",
                            url: "/teams/" + t.team + "/notifications/"
                        }
                    }),
                    mcw.readNotification(t.guid),
                    window.focus(),
                    this.cancel()
                },
                mcw.playAudio("notification", "/assets/notification-cc3cfeed3b317b42296450911fae479a.mp3"),
                n.show(),
                setTimeout(function() {
                    n && n.cancel()
                },
                1e4)
            }
        },
        metaKey: function(e) {
            var t = /Mac/.test(navigator.userAgent);
            return t ? e.metaKey: e.ctrlKey
        },
        playNotifySound: function() {
            var t = e("#notify-sound");
            t.length || (t = e('<audio id="notify-sound">						<source src="/assets/notification-cc3cfeed3b317b42296450911fae479a.mp3" type="audio/mpeg" />					</audio>').appendTo("body")),
            t = t.get(0),
            e.browser.chrome && t.load(),
            t.play()
        },
        prettyDate: function(e, t) {
            var n = moment(e, t),
            r = moment(),
            i = r.diff(n);
            if (i < 0) return "刚刚";
            if (n.diff(moment().add("d", -1).startOf("day")) < 0) return n.format("M月D日");
            if (n.diff(moment().startOf("day")) < 0) return "昨天";
            if (i < 6e4) return "刚刚";
            if (i >= 6e4 && i < 36e5) return Math.round(i / 6e4).toFixed(0) + "分钟前";
            if (i >= 36e5 && i < 864e5) return Math.round(i / 36e5).toFixed(0) + "小时前"
        },
        readNotification: function(t) {
            var n = e("#notification-count"),
            r = Math.max(0, n.text() * 1 - 1);
            n.toggleClass("unread", r > 0).text(r);
            var i = e(".noti-pop-list");
            i.find(".notice[data-notification-guid=" + t + "]").remove(),
            i.find(".notice").length || (i.html("").hide(), e(".noti-pop-empty").show())
        },
        adjustDate: function(t) {
            e("[data-abstime]", t).each(function() {
                var t = e(this);
                t.text(mcw.prettyDate(t.data("abstime"), "YYYY-MM-DD HH:mm:ss Z")).removeAttr("data-abstime")
            })
        },
        adjustPermission: function(t) {
            t = e(t).is("[data-visible-to]") ? e(t
            ) : e("[data-visible-to]", t),
            t.each(function() {
                var t = e(this).hide(),
                n = t.data("visible-to").split(",");
                mcw.me.admin && e.inArray("admin", n) > -1 && t.show();
                if (e.inArray("creator", n) > -1) {
                    var r = t.closest("[data-author-guid]");
                    r.length && mcw.me.guid == r.data("author-guid") && t.show()
                }
            })
        }
    });
    if (e.ui && e.ui.sortable) {
        var t = e.ui.sortable.prototype._mouseStart;
        e.ui.sortable.prototype._mouseStart = function(e, n, r) {
            this._trigger("beforestart", e, this._uiHash()),
            t.apply(this, [e, n, r])
        };
        var n = e.fn.scrollParent;
        e.fn.scrollParent = function() {
            var t = n.apply(this, arguments);
            return t.is("html") ? e(document) : t
        }
    }
    if (e.ui && e.ui.draggable) {
        var r = e.ui.draggable.prototype._mouseStart;
        e.ui.draggable.prototype._mouseStart = function(e, t, n) {
            this._trigger("beforestart", e, this._uiHash()),
            r.apply(this, [e, t, n])
        }
    }
} (jQuery),

//项目内容页各类控制 https://tower.im/projects/06153e5a411c416c8981e3879466f087/

function(e) {
    function t(t) {
        e(".todolist-form.new").show().find(".todolist-name").focus(),
        e(".init-todo-empty, .init-todo-completed").hide()
    }
    function n(t) {
        e(".todolist-form.new").find(".todolist-name").val("").removeClass("error").end().hide(),
        e(".init-todo-empty, .init-todo-completed").show()
    }
    function i(t) {
        var n = e(this).data("request-members");
        mcw.members || (mcw.members = {}),
        mcw.members[n] ? s(".todo-assignee[disabled]", mcw.members[n]) : r || (r = e.ajax({
            url: "/projects/" + n + "/mates",
            type: "get",
            success: function(e) {
                mcw.members[n] = e,
                s(".todo-assignee[disabled]", e),
                r = null
            }
        }))
    }
    function s(t, n) {
        e(t).each(function() {
            var t = e(this);
            t.is("select") || (t = t.find("select"));
            var r = t.find("option.loading");
            if (r.length < 1) return;
            n.length && e.each(n, 
            function() {
                e("<option />").text(this.nickname).val(this.guid).insertAfter(r)
            }),
            r.remove(),
            e("<option disabled>-----</option>").prependTo(t);
            var i = t.find("option[value=" + mcw.me.guid + "]");
            i.text(i.text() + " (我自己)").prependTo(t),
            t.val(t.data("selected-member") || -1).removeAttr("data-selected-member").removeAttr("disabled");
            var s = i.next(),
            o = s.next();
            o.is("[disabled]") && (s.remove(), o.remove())
        })
    }
    function o(t) {
        function h() {
            if (n.hasClass("link-todo-due")) {
                var t = i.find(".todo-due-date").val();
                n.find(".due").text(t || "没有截止时间").attr("data-date", t || ""),
                n.next(".todo-due-date").val(t ? moment(t).valueOf() : "")
            } else {
                var r = n.closest(".todo"),
                s = r.find(".todo-content a").text(),
                o = i.find(".todo-assignee").val(),
                t = i.find(".todo-due-date").val(),
                u = {
                    todo_content: s,
                    assignee_guid: o,
                    due_at: t ? moment(t).valueOf() : undefined
                };
                mcw.tinyLoading(n),
                e.ajax({
                    url: r.find(".todo-actions .edit").attr("href"),
                    data: u,
                    success: function(t) {
                        var n = e(t.html);
                        r.replaceWith(n),
                        mcw.adjustTodo(n),
                        mcw.setTodoFilter(),
                        e(".workspace .page:last").trigger("todoupdate", [n])
                    }
                })
            }
            mcw.popover(n, "hide")
        }
        var n = e(this);
        if (n.hasClass("disabled")) return;
        var r = n.data("popover");
        if (r) mcw.popover(n, "hide");
        else {
            var i = mcw.template("tpl-todo-popover"),
            o = n.find(".due").attr("data-date") || null,
            u = i.find(".todo-due-date").val(o);
            if (n.hasClass("link-todo-due")) i.find(".select-assignee").remove(),
            i.find("h3").remove();
            else {
                var a = n.find(".assignee").attr("data-guid") || -1,
                f = n.closest(".todo").data("project-guid"),
                l = i.find(".todo-assignee").on("change", 
                function(e) {
                    h()
                });
                l.attr("data-selected-member", a),
                mcw.members[f] && l.is("[disabled]") && s(l, mcw.members[f])
            }
            i.find(".shortcuts a").click(function(t) {
                t.preventDefault();
                var n = e(this),
                r = "";
                n.hasClass("today") ? r = moment().format("YYYY-MM-DD") : n.hasClass("tomorrow") ? r = moment().add("days", 1).format("YYYY-MM-DD") : n.hasClass("this-week") ? r = moment().day(5).format("YYYY-MM-DD") : n.hasClass("next-week") && (r = moment().day(12).format("YYYY-MM-DD")),
                c.setSelectedDate(r),
                h()
            }),
            o ? i.find(".no-due-date").click(function(e) {
                e.preventDefault(),
                c.setSelectedDate(null),
                h()
            }) : i.find(".no-due-date").remove();
            var c = mcw.datepicker(u, {
                inline: !0,
                onSelect: function(e) {
                    h()
                }
            });
            mcw.popover(n, {
                content: i
            })
        }
        return ! 1
    }
    function u(t, n) {
        var r = e(n.html);
        e(".todolists").prepend(r),
        e(t.target).find(".btn-cancel-todolist").click().end().find(".todolist-name").val(""),
        r.find(".btn-new-todo").click(),
        mcw.sortTodos(r.find(".todos-uncompleted")),
        e(".init-todo-empty, .init-todo-completed").remove(),
        e(".filters-wrap").show()
    }
    function a(t) {
        t.keyCode === 13 ? (t.preventDefault(), e(t.currentTarget).find("button[type=submit]").click()) : t.keyCode === 27 && (t.preventDefault(), e(t.currentTarget).find(".btn-cancel-todolist, .btn-cancel-update-todolist").click())
    }
    function f(t) {
        t.preventDefault();
        var n = e(t.currentTarget),
        r = n.parent(),
        i = r.next(".todo-form.new");
        if (!i.length) {
            i = mcw.template("tpl-todo-form").insertAfter(r),
            i.addClass("new").find("form").attr("action", n.data("url")).find("textarea").autosize().end().find(".edit-buttons").remove();
            var o = n.data("request-members"),
            u = i.find(".todo-assignee").attr("data-selected-member", "-1");
            mcw.members[o] && u.is("[disabled]") && s(u, mcw.members[o])
        }
        i.show().find("textarea").focus(),
        r.hide()
    }
    function l(t) {
        var n = e(t.currentTarget),
        r = n.parents(".todo-form.new"),
        i = r.prev();
        r.hide().find(".todo-content").val("").removeClass("error"),
        i.show()
    }
    function c(t, n) {
        var r = e(n.html),
        i = e(t.target);
        i.find("textarea.todo-content").val("").focus().end().closest(".todolist").find(".todos-uncompleted").append(r),
        mcw.setTodoFilter(),
        mcw.adjustTodo(r)
    }
    function h(t, n, r) {
        e(t.target).closest(".page").attr("id") == "page-todolist" && mcw.globalLoading("正在删除任务列表...")
    }
    function p(t, n) {
        var r = e(t.target).closest(".todolist");
        r.closest(".page").attr("id") == "page-todolist" ? (mcw.globalLoading("hide"), mcw.stack({
            url: "/projects/" + r.data("project-guid") + "/",
            root: !0
        })) : r.fadeOut(function() {
            e(this).remove()
        })
    }
    function d(t, n) {
        var r = e(n.html),
        i = e(t.target).closest(".title");
        i.hide().after(r),
        mcw.selectText(r.find(".todolist-name").focus())
    }
    function v(t) {
        e(t.currentTarget).parents(".todolist-form.edit").prev(".title").show().end().remove()
    }
    function m(t) {
        var n = e(this).data("url");
        e.ajax({
            url: n
        })
    }
    function g(t, n, r, i) {
        var s = e(t.target),
        o = s.closest(".todolist").find(".title h4 a");
        o.text(s.find("input.todolist-name").val()).closest(".title").show(),
        s.parent(".todolist-form.edit").remove()
    }
    function y(t, n) {
        if (n.success) {
            var r = e(this),
            i = r.parents(".todolist:first"),
            s = i.closest(".page");
            s.is("#page-todolist") ? i.addClass("todolist-completed") : i.fadeOut(function() {
                if (s.is("#page-todolists")) {
                    var t = e(".todolists-completed");
                    t.find("a").length && t.append(","),
                    t.append(i.find(".title h4 a"))
                }
                e(this).remove()
            })
        }
    }
    function b(t, n) {
        if (n.success) {
            var r = e(this),
            i = r.parents(".todolist:first");
            i.removeClass("todolist-completed")
        }
    }
    function w(t, n, r) {
        e(t.target).closest(".page").attr("id") == "page-todo" && mcw.globalLoading("正在删除任务...")
    }
    function E(t, n) {
        var r = e(t.target).closest(".todo");
        r.closest(".page").is("#page-todo") ? (mcw.globalLoading("hide"), mcw.stack({
            url: "/projects/" + r.data("project-guid") + "/",
            root: !0
        })) : r.fadeOut(function() {
            r.remove(),
            e(".workspace .page:last").trigger("todoremove", [r])
        })
    }
    function S(t) {
        t.preventDefault();
        var n = e(t.currentTarget),
        r = n.closest(".todo"),
        i = r.next(".todo-form.edit");
        if (!i.length) {
            i = mcw.template("tpl-todo-form").insertAfter(r),
            i.addClass("edit").find("form").attr("action", n.attr("href")).end().find(".create-buttons").remove();
            var o = n.data("request-members"),
            u = i.find(".todo-assignee").attr("data-selected-member", r.find(".assignee").data("guid") || -1);
            mcw.members[o] && u.is("[disabled]") && s(u, mcw.members[o])
        }
        var a = r.find(".todo-assign-due .due").data("date") || null;
        i.find(".link-todo-due .due").text(a || "没有截止时间").attr("data-date", a),
        a && i.find("input[name=due_at]").val(moment(a).valueOf());
        var f = i.find("textarea").val(r.find(".todo-content a").text());
        mcw.selectText(f),
        i.show().find("textarea").autosize(),
        r.hide()
    }
    function x(t) {
        var n = e(t.currentTarget).closest(".todo-form.edit"),
        r = n.find(".link-todo-due"),
        i = r.data("popover");
        i && mcw.popover(r, "hide"),
        n.prev(".todo").show().end().remove()
    }
    function T(t, n, r, i) {
        var s = e(t.target).parents(".todo-form.edit"),
        o = s.prev(".todo"),
        u = e(n.html),
        a = n.assigneeGuid,
        f = e("#page-member");
        s.remove(),
        o.replaceWith(u),
        mcw.setTodoFilter(),
        mcw.adjustTodo(u),
        mcw.adjustDate(u),
        e(".workspace .page:last").trigger("todoupdate", [u]);
        var l = u.find(".todo-content");
        mcw.highlight(l, undefined, l.css("backgroundColor"))
    }
    function C(t) {
        var n = e(t.target),
        r = n.is(":checked"),
        i = n.closest(".todo"),
        s = i.closest(".todolist"),
        o = i.data("guid"),
        u = i.data("project-guid"),
        a = "/projects/" + u + "/todos/" + o + (r ? "/complete/": "/reopen/");
        N && (N.abort(), N = null),
        N = e.ajax({
            url: a,
            dataType: "json",
            type: "post",
            success: function(t) {
                function a() {
                    e("#page-todo").length ? i.replaceWith(n) : r ? (i.fadeTo(200, 0), i.slideUp(200, 
                    function() {
                        i.remove(),
                        n.prependTo(o),
                        e(".workspace .page:last").trigger("todocomplete", [i])
                    })) : i.fadeOut(function() {
                        i.remove(),
                        n.appendTo(o),
                        mcw.setTodoFilter(),
                        e(".workspace .page:last").trigger("todoreopen", [i])
                    }),
                    mcw.adjustDate(n),
                    mcw.adjustTodo(n)
                }
                var n = e(t.html),
                o = r ? s.find(".todos-completed") : s.find(".todos-uncompleted"),
                u = e(".runner.on", i);
                u.length ? (mcw.transitionEnd(i, 
                function() {
                    setTimeout(function() {
                        a()
                    },
                    500)
                }), u.removeClass("on")) : a()
            }
        })
    }
    function k(t) {
        t.keyCode === 13 && !mcw.metaKey(t) ? (t.preventDefault(), e(t.currentTarget).find("button[type=submit]").click()) : t.keyCode === 27 && (t.preventDefault(), e(t.currentTarget).find(".btn-cancel-todo, .btn-cancel-update-todo").click())
    }
    e(function() {
        var r = e(".wrapper");
        r.on("click", ".btn-new-todolist", t).on("click", ".btn-cancel-todolist", n).on("ajax:success", ".todolist-form.new .form", u).on("keydown", ".todolist-form", a).on("validate", ".todolist-form form", 
        function(e, t, n) {
            var r = {
                valid: !0
            };
            return t ? t.length > 255 && (r.valid = !1, r.errorMsg = "", mcw.message({
                msg: "任务列表名称最长255个字符"
            })) : (r.valid = !1, r.errorMsg = ""),
            r
        }),
        r.on("click", ".btn-new-todo", f).on("click", ".btn-cancel-todo", l).on("click", ".link-todo-due", o).on("ajax:success", ".todo-form.new .form", c).on("keydown", ".todo-form", k).on("validate", ".todo-form form", 
        function(e, t, n) {
            var r = {
                valid: !0
            };
            return t ? t.length > 1e3 && (r.valid = !1, r.errorMsg = "", mcw.message({
                msg: "任务内容最长1000个字符"
            })) : (r.valid = !1, r.errorMsg = ""),
            r
        }),
        r.on("ajax:success", ".todo .todo-actions .run", 
        function(t, n) {
            function o() {
                var t = e(".runner", r).removeClass("on");
                i.replaceWith(r),
                setTimeout(function() {
                    t.addClass("on")
                },
                10),
                mcw.adjustTodo(r)
            }
            var r = e(n.html),
            i = e(t.target).closest("li.todo"),
            s = e.grep(e("li.todo.running:has(.assignee)"), 
            function(t, n) {
                return e(".assignee", t).data("guid") === mcw.me.guid ? !0: !1
            });
            i.hasClass("hl") && r.addClass("hl"),
            s.length ? (s = e(s[0]), mcw.transitionEnd(s, o), s.removeClass("running").find(".runner").removeClass("on")) : o()
        }).on("ajax:success", ".todo .todo-actions .pause", 
        function(t, n) {
            var r = e(n.html),
            i = e(t.target).closest("li.todo");
            i.hasClass("hl") && r.addClass("hl"),
            mcw.transitionEnd(i, 
            function() {
                i.replaceWith(r),
                mcw.adjustTodo(r)
            }),
            e(".runner", i).removeClass("on")
        }),
        r.on("ajax:success", ".todolist-actions .del", p).on("ajax:beforeSend", ".todolist-actions .del", h).on("ajax:success", ".todolist-actions .edit", d).on("click", ".btn-cancel-update-todolist", v).on("click", ".todolist-stick-checkbox", m).on("ajax:success", ".todolist-form.edit .form", g).on("ajax:success", ".todolist-actions .close", y).on("ajax:success", ".todolist-actions .reopen", b),
        r.on("ajax:success", ".todo-actions .del", E).on("ajax:beforeSend", ".todo-actions .del", w).on("click", ".todo-actions .edit", S).on("click", ".btn-cancel-update-todo", x).on("ajax:success", ".todo-form.edit .form", T).on("click", ".todo .todo-assign-due", o).on("mouseenter", "[data-request-members]", i),
        r.on("click", ".todo input[type=checkbox]", C),
        r.on("change", ".filters select", 
        function(t) {
            var n = e(t.currentTarget),
            r = n.val();
            n.is("#filter-assignee") ? localStorage.todo_hl_assignee = r: n.is("#filter-due") && (localStorage.todo_hl_due = r),
            mcw.setTodoFilter()
        }),
        mcw.adjustTodo()
    });
    var r = null,
    N;
    e.extend(mcw, {
        sortTodos: function(t) {
            var t = t || e(".todos-uncompleted");
            if (!t.is(".todos-uncompleted")) return;
            t.sortable({
                axis: "y",
                handle: ".todo-content",
                items: ".todo",
                cursor: "pointer",
                cursorAt: {
                    left: 30,
                    top: 20
                },
                tolerance: "pointer",
                helper: "clone",
                placeholder: "todo-placeholder",
                connectWith: ".todos-uncompleted",
                start: function(e, n) {
                    t.addClass("sorting");
                    var r = (n.helper.outerHeight(!0) - 2) / 2;
                    n.placeholder.css({
                        height: r,
                        marginBottom: r
                    })
                },
                stop: function(n, r) {
                    var i = r.item,
                    s = i.closest(".todos").find(".todo").map(function() {
                        return e(this).data("guid")
                    }).get(),
                    o = i.closest(".todolist").data("guid"),
                    u = i.data("guid"),
                    a = i.data("project-guid");
                    e.ajax({
                        url: "/projects/" + a + "/todos/" + u + "/reorder/",
                        data: {
                            list_guid: o,
                            guids: s.join(",")
                        }
                    }),
                    t.removeClass("sorting")
                }
            })
        },
        sortTodolists: function(t) {
            var t = t || e(".todolists");
            if (!t.is(".todolists")) return;
            t.sortable({
                axis: "y",
                handle: ".title h4 a",
                items: ".todolist",
                cursor: "pointer",
                helper: "clone",
                tolerance: "pointer",
                placeholder: "todolist-placeholder",
                beforestart: function(e, t) {
                    var n = t.item.parent(".todolists"),
                    r = n.children(".todolist"),
                    i = t.item.prevAll(".todolist"),
                    s = t.item.nextAll(".todolist"),
                    o = n.outerHeight(),
                    u = 54,
                    a = t.item.offset().top - n.offset().top,
                    f = a - i.length * u,
                    l = o - r.length * u - f;
                    r.addClass("collapse").children(":not(.title)").hide(),
                    n.css({
                        paddingTop: f,
                        paddingBottom: l
                    })
                },
                stop: function(e, t) {
                    var n = t.item;
                    n.parent().css({
                        paddingTop: 0,
                        paddingBottom: 0
                    }).find(".todolist").removeClass("collapse").children("ul").show(),
                    mcw.scrollTo(n),
                    setTimeout(function() {
                        mcw.highlight(n)
                    },
                    500)
                },
                update: function(t, n) {
                    var r = n.item,
                    i = r.parent().find(".todolist:visible").map(function() {
                        return e(this).data("guid")
                    }).get().reverse(),
                    s = r.data("guid"),
                    o = r.data("project-guid"),
                    u = {
                        guids: i.join(",")
                    };
                    e.ajax({
                        url: "/projects/" + o + "/lists/" + s + "/reorder/",
                        data: u
                    })
                }
            })
        },
        setTodoFilter: function() {
            if (!e(".filters").length) return;
            var t = e(".todos-uncompleted .todo");
            if (!t.length) return;
            var n = !0,
            r = !0,
            i = localStorage.todo_hl_assignee || e("#filters-assignee").val(),
            s;
            localStorage.todo_hl_due ? s = parseInt(localStorage.todo_hl_due) : s = parseInt(e("#filter-due").val()),
            t.filter(".hl").removeClass("hl");
            switch (i) {
            case "0":
                n = !1;
                break;
            case "-1":
                t = e.grep(t, 
                function(t, n) {
                    return ! e(".assignee", t).length
                });
                break;
            default:
                t = e.grep(t, 
                function(t, n) {
                    return e(".assignee", t).data("guid") === i
                })
            }
            var o = moment(),
            u = moment();
            switch (s) {
            case - 1: r = !1;
                break;
            case 0:
                u = u.sod(),
                t = e.grep(t, 
                function(t) {
                    var n = e(".due", t).data("date");
                    return n && moment(n).diff(u) == 0 ? !0: !1
                });
                break;
            case 1:
                u = u.add("days", 1).sod(),
                t = e.grep(t, 
                function(t) {
                    var n = e(".due", t).data("date");
                    return n && moment(n).diff(u) == 0 ? !0: !1
                });
                break;
            case 2:
                o.day() == 0 ? (o = o.day( - 6).sod(), u = u.sod()) : (o = o.day(1).sod(), u = u.day(7).sod()),
                t = e.grep(t, 
                function(t) {
                    var n = e(".due", t).data("date");
                    return n && moment(n).diff(u) <= 0 && moment(n).diff(o) >= 0 ? !0: !1
                });
                break;
            case 3:
                o = o.add("weeks", 1),
                u = u.add("weeks", 1),
                o.day() == 0 ? (o = o.day( - 6).sod(), u = u.sod()) : (o = o.day(1).sod(), u = u.day(7).sod()),
                t = e.grep(t, 
                function(t) {
                    var n = e(".due", t).data("date");
                    return n && moment(n).diff(u) <= 0 && moment(n).diff(o) >= 0 ? !0: !1
                });
                break;
            case 4:
                u = u.add("days", -1).sod(),
                t = e.grep(t, 
                function(t) {
                    var n = e(".due", t).data("date");
                    return n && moment(n).diff(u) <= 0 ? !0: !1
                });
                break;
            case 5:
                u = u.add("weeks", 2),
                u.day() == 0 ? u = u.day( - 6).sod() : u = u.day(1).sod(),
                t = e.grep(t, 
                function(t) {
                    var n = e(".due", t).data("date");
                    return ! n || moment(n).diff(u) >= 0 ? !0: !1
                });
                break;
            default:

            }
            n || r ? (e(t).addClass("hl"), e(".filter-desc").show()) : e(".filter-desc").hide(),
            localStorage.todo_hl_assignee = i,
            localStorage.todo_hl_due = s
        },
        initTodoFilter: function() {
            localStorage.todo_hl_assignee ? e("#filter-assignee").val(localStorage.todo_hl_assignee) : e("#filter-assignee").length && (localStorage.todo_hl_assignee = e("#filter-assignee").val()),
            localStorage.todo_hl_due && e.isNumeric(localStorage.todo_hl_due) ? e("#filter-due").val(localStorage.todo_hl_due) : e("#filter-due").length && (localStorage.todo_hl_due = e("#filter-due").val() * 1),
            mcw.setTodoFilter()
        },
        adjustTodoFilter: function() {
            var t = e("#filter-assignee"),
            n = t.find("option[value=" + mcw.me.guid + "]");
            n.text(n.text().replace(" (我自己)", "") + " (我自己)").insertAfter(t.find("[value=0]").next())
        },
        adjustTodo: function(t) {
            var n = e(t).is(".todo") ? e(t) : e(".todo", t),
            r = moment().startOf("day").toDate();
            n.find(".todo-assign-due").each(function(t, n) {
                var i = e(this).find(".due").data("date");
                if (i) {
                    var s = moment(i).toDate();
                    s < r && e(this).addClass("delay")
                }
            }),
            n.each(function(t, n) {
                var n = e(n),
                r = e(".assignee", n); (!r.length || r.data("guid") !== mcw.me.guid) && n.find(".run, .pause").remove()
            });
            var i = e(".workspace .page:last");
            i.is("[data-archived], [data-locked], [data-deleted]") && (n.find("input:checkbox").attr("disabled", "disabled"), n.find(".todo-assign-due").addClass("disabled"))
        }
    })
} (jQuery),

//讨论内容页编辑器点击后展开 https://tower.im/projects/06153e5a411c416c8981e3879466f087/messages/48ff6ec4535c4dc2a69a9cb723442454/

function(e) {
    function t(t, n) {
        e(t.target).parents(".comment:first").fadeOut(function() {
            e(this).remove()
        })
    }
    function n(t, n) {
        var r = e(n.html),
        i = e("textarea.comment-content", r),
        s = e(t.target).parents(".comment:first");
        s.hide(),
        r.insertAfter(s),
        mcw.editor(i)
    }
    function r(t) {
        var n = e(this).closest(".form"),
        r = n.find(".editor").data("editor");
        r.destroyEditor(),
        e(t.currentTarget).parents(".comment-form.edit").prev().show().end().remove()
    }
    function i(t, n, r, i) {
        var s = e(t.target).parents(".comment-form.edit"),
        o = s.prev(),
        u = e(n.html).hide();
        o.replaceWith(u),
        u.show(),
        s.remove(),
        mcw.adjustDate(u),
        mcw.adjustPermission(u)
    }
    function s(t) {
        var n = e(t.currentTarget).closest(".comment-form.new"),
        r = n.find(".editor").data("editor");
        r.destroyEditor(),
        e(".notify, .form-buttons, .fake-textarea", n).toggle()
    }
    e(function() {
        e(".wrapper").on("click", ".form-new-comment .fake-textarea", 
        function(t) {
            t.preventDefault();
            var n = e(this).hide().parents(".form:first");
            e(".notify, .form-buttons", n).show(),
            n.find(".member-list input:checked").length ? (n.find(".receiver, .change-notify").show(), n.find(".select-all, .notify-title + .form-field").hide()) : (n.find(".receiver, .change-notify").hide(), n.find(".select-all, .notify-title + .form-field").show());
            var r = e("textarea.comment-content", n);
            mcw.editor(r)
        }).on("ajax:success", ".comment-actions .del", t).on("ajax:success", ".comment-actions .edit", n).on("click", ".btn-cancel-update-comment", r).on("ajax:success", ".comment-form.edit .form", i).on("click", ".btn-cancel-create-comment", s).on("ajax:success", ".comment-form.new .form", 
        function(t, n) {
            var r = e(n.html).hide(),
            i = e(t.target).closest(".comment-form.new"),
            s = i.find(".editor").data("editor");
            r.insertBefore(i).fadeIn(),
            s.destroyEditor(),
            e(".notify, .form-buttons, .fake-textarea", i).toggle(),
            mcw.adjustCCList(),
            mcw.adjustDate(r),
            mcw.adjustPermission(r)
        })
    }),
    e.extend(mcw, {
        adjustCCList: function() {
            var t = e(".comment-form, .form-new-discussion"),
            n = t.find(".receiver"),
            r = t.find(".member-list");
            r.find("input[value=" + mcw.me.guid + "]:checkbox").closest("li").remove();
            if (!n.length) return;
            n.empty();
            var i = r.find("input:checked");
            if (i.length) {
                var s = "";
                i.each(function(t, n) {
                    var r = e(this),
                    i = r.val(),
                    o = r.parent().text();
                    t > 0 && (s += '<span class="sp">, </span>'),
                    s += '<span data-guid="' + i + '">' + o + "</span>"
                }),
                n.html(s)
            } else n.hide().next(".change-notify").hide().next(".select-all").show()
        },
        adjustAuthor: function() {
            var t = e(".comment-form, .form-new-discussion");
            t.find(".avatar-wrap").attr("href", "/members/" + mcw.me.guid),
            t.find("img.avatar").attr("src", mcw.me.avatar)
        }
    })
} (jQuery),

//项目内容页标记处理及文件上传 https://tower.im/projects/06153e5a411c416c8981e3879466f087/
function(e) {
    function t(t, n, r) {
        e(t).each(function() {
            var t = e(this),
            i = t.find(".label-list").empty();
            e.each(n, 
            function() {
                var t = e("<a/>", {
                    href: "javascript:;",
                    "class": "folder-item",
                    text: this.name
                }).attr("data-guid", this.guid).appendTo(i);
                this.guid == r && t.addClass("current")
            }),
            t.find(".txt-new-label").removeAttr("disabled")
        })
    }
    function n(t, n) {
        var r;
        e.each(mcw.folders[n], 
        function(e) {
            this.guid == t && (r = e)
        }),
        mcw.folders[n].splice(r, 1)
    }
    e(function() {
        e(document).on("ajax:success", ".file .link-delete", 
        function(t) {
            var n = e(this).closest(".file");
            n.fadeOut(function() {
                var t = e(".workspace .page:last");
                n.trigger("filedelete", [n]),
                n.remove()
            })
        }).on("click", ".file .link-label", 
        function(n) {
            n.preventDefault();
            var r = e(this),
            i = r.data("popover");
            if (r.hasClass("loading") || r.hasClass("disabled")) return;
            if (i) mcw.popover(r, "hide");
            else {
                var s = mcw.template("tpl-label-popover"),
                o = s.find(".label-list").data("project-guid");
                mcw.folders[o] && t(s, mcw.folders[o], r.data("guid")),
                r.hasClass("no-label") ? s.find(".remove-label").hide() : s.find("h3").text("更换标签"),
                mcw.popover(r, {
                    content: s
                })
            }
            return ! 1
        }).on("mousedown", ".label-popover .link-remove-label", 
        function(t) {
            t.preventDefault();
            var r = e(this),
            i = r.closest(".popover"),
            s = i.data("target"),
            o = s.data("guid");
            mcw.popover(s, "hide"),
            s.addClass("loading"),
            e.ajax({
                url: s.data("url"),
                data: {
                    to: !1
                },
                success: function(t) {
                    s.text("标记文件").addClass("no-label").removeClass("loading").data("guid", "");
                    if (t.deleted) {
                        var r = i.find(".label-list").data("project-guid");
                        n(t.deleted, r)
                    }
                    if (o) {
                        var u = e(".file-links .link-folder[data-guid=" + o + "] span"),
                        a = u.text().match(/\d+/g);
                        a = a ? Math.max(0, a[0] * 1 - 1) : 0,
                        u.text("(" + a + ")")
                    }
                }
            })
        }).on("click", ".label-popover .folder-item", 
        function(t) {
            t.preventDefault();
            var r = e(this),
            i = r.closest(".popover"),
            s = i.data("target"),
            o = s.data("guid"),
            u = r.data("guid");
            mcw.popover(s, "hide"),
            s.addClass("loading"),
            e.ajax({
                url: s.data("url"),
                data: {
                    to: u
                },
                success: function(t) {
                    s.text(r.text()).removeClass("no-label").removeClass("loading").data("guid", r.data("guid"));
                    if (t.deleted) {
                        var a = i.find(".label-list").data("project-guid");
                        n(t.deleted, a)
                    }
                    if (o) {
                        var f = e(".file-links .link-folder[data-guid=" + o + "] span"),
                        l = f.text().match(/\d+/g);
                        l = l ? Math.max(0, l[0] * 1 - 1) : 0,
                        f.text("(" + l + ")")
                    }
                    var c = e(".file-links .link-folder[data-guid=" + u + "] span"),
                    l = c.text().match(/\d+/g);
                    l = l ? l[0] * 1 + 1: 0,
                    c.text("(" + l + ")")
                }
            })
        }).on("keydown", ".label-popover .txt-new-label", 
        function(t) {
            if (t.which != 13) return;
            var n = e(this),
            r = n.val();
            if (!r) {
                n.addClass("error");
                return
            }
            n.removeClass("error");
            var i = n.closest(".popover"),
            s = i.data("target"),
            o = s.data("guid");
            mcw.popover(s, "hide"),
            s.addClass("loading"),
            e.ajax({
                url: s.data("url"),
                data: {
                    name: r
                },
                success: function(t) {
                    s.text(r).removeClass("no-label").removeClass("loading").data("guid", t.guid);
                    var u = i.find(".label-list").data("project-guid");
                    mcw.folders[u].splice(0, 0, {
                        name: t.name,
                        guid: t.guid
                    }),
                    n.val("");
                    if (o) {
                        var a = e(".file-links .link-folder[data-guid=" + o + "] span"),
                        f = a.text().match(/\d+/g);
                        f = f ? Math.max(0, f[0] * 1 - 1) : 0,
                        a.text("(" + f + ")")
                    }
                    e("<a/>", {
                        "class": "link-folder",
                        "data-stack": "",
                        "data-guid": t.guid,
                        href: "/projects/" + u + "/dirs/" + t.guid + "/"
                    }).append(t.name + "(<span>1</span>)").insertAfter(".file-links .link-more-files")
                }
            }),
            e(document).off(".folder")
        }).on("mouseover", "[data-request-labels]", 
        function() {
            var n = e(this),
            r = n.data("request-labels");
            mcw.folders || (mcw.folders = {}),
            mcw.folders[r] ? t(".label-popover", mcw.folders[r], n.data("guid")) : e.ajax({
                url: "/projects/" + r + "/folders.json",
                type: "get",
                success: function(e) {
                    mcw.folders[r] = e,
                    t(".label-popover", e, n.data("guid"))
                }
            }),
            n.removeAttr("data-request-labels").attr("data-project-guid", r)
        })
    }),
    e.extend(window.mcw, {
        initUpload: function(t) {
            var n = t.btn ? e(t.btn) : e(".btn-upload-file"),
            r = t.container ? e(t.container) : e(".file-list"),
            i = n.data("url"),
            s;
            s = mcw.upload(n, {
                action: i,
                beforeUpload: function(n) {
                    var i = mcw.template("tpl-upload-file", {
                        id: n.id,
                        name: n.name
                    });
                    r.prepend(i),
                    mcw.loadImage(n.obj, 
                    function(e) {
                        if (!e) {
                            var t = "/assets/file_icons/",
                            r = t + "file_extension_" + n.extension + ".png";
                            mcw.loadImage(r, 
                            function(e) {
                                e ? i.find(".file-thumb img").attr("src", e.src) : i.find(".file-thumb img").attr("src", t + "file_extension_others.png")
                            })
                        } else i.find(".file-thumb").attr({
                            "data-origin-src": e.src,
                            "data-origin-name": n.name,
                            "data-origin-size": e.width + "," + e.height
                        }).find("img").attr("src", e.src)
                    });
                    if (window.File && window.FileList) {
                        var o = 0;
                        n.size >= 1048576 ? o = (n.size / 1048576).toFixed(1) + "M": o = (n.size / 1024).toFixed(0) + "K"
                    } else i.addClass("ie");
                    i.find(".size").text(o).end().find(".link-cancel").text("取消上传").attr("title", "取消上传").click(function() {
                        var e = i.attr("fileid");
                        e && i.hasClass("uploading") && s.cancel(e),
                        i.fadeOut(function() {
                            t.onCancel && t.onCancel(i)
                        })
                    }),
                    t.beforeUpload && t.beforeUpload();
                    if (t.countEl) {
                        var u = e(t.countEl),
                        a = u.text().replace(/\d+/, 
                        function(e) {
                            return e * 1 + 1
                        });
                        u.text(a).show()
                    }
                },
                onProgress: function(e, t, n) {
                    var i = r.find(".file[fileid=" + e.id + "]"),
                    s = (t / n * 100).toFixed(0) + "%";
                    i.find(".progress-bar span").width(s),
                    i.find(".percent").text(s)
                },
                onSuccess: function(n, i) {
                    var s = r.find(".file#file-upload-" + n.id),
                    o = e(i.html).show();
                    s.replaceWith(o),
                    e(".init.init-file").remove(),
                    t.onSuccess && t.onSuccess(n, i)
                },
                onValidate: function(e, t) {
                    return e.size && e.size / 1048576 > 50 ? (mcw.message({
                        msg: '附件 <em style="color: #ee6500;">' + e.name + "</em> 大小超过50MB, 无法完成上传",
                        width: 500
                    }), !1) : !0
                },
                onCancel: function(e) {},
                onError: function(e, t) {},
                onComplete: function(e, t) {}
            })
        },
        adjustFile: function(t) {
            var n = e(".workspace .page:last"),
            r = e(t).is(".file") ? e(t) : e(".file", t);
            n.is("[data-archived], [data-locked], [data-deleted]") && r.find(".link-label").addClass("disabled")
        }
    })
} (jQuery),

//忘记密码页面 https://tower.im/users/forgot_password

function(e) {
    e(function() {
        var t = e("#page-forgot-password");
        if (t.length < 1) return;
        t.on("ajax:success", "form.form", 
        function(t, n) {
            var r = e("#email").val(),
            i = e(".center-box .bd").empty();
            mcw.template("template-email-sent", {
                email: r
            }).appendTo(i)
        })
    })
} (jQuery),

//已邀请成员页面 https://tower.im/invitations/7e2c4bcc6ed8419fbe6a6ba69a49cf3e/

function(e) {
    var t = "page-member";
    page = "#" + t,
    e(function() {
        e("body").on("ajax:beforeSend", page + " #link-cancel-invitation", 
        function(e) {
            mcw.globalLoading("正在取消邀请...")
        }).on("ajax:error", page + " #link-cancel-invitation", 
        function(e) {
            mcw.globalLoading("hide")
        })
    })
} (jQuery),

//邀请页面 https://tower.im/invite/

function(e) {
    var t = "page-invite",
    n = "#" + t;
    e(function() {
        e("body").on("submit", n + " .form-invite", 
        function(t) {
            var n = e(this),
            r = !0,
            i = e.grep(e("input.invite-email"), 
            function(t, n) {
                return e.trim(e(t).val()) !== ""
            });
            return e("input.invite-email:first").closest(".form-item").find("p.error").remove(),
            i.length ? (e.each(i, 
            function(n, i) {
                var i = e(i),
                s = i.val(),
                o = e.trim(s);
                if (!mcw.validate.email(o).valid) {
                    var u = s.indexOf(o),
                    a = o + " 不是一个正确的邮箱地址";
                    return mcw.selectText(t.currentTarget, u, o.length),
                    e('<p class="error">' + a + "</p>").appendTo(i.parent()),
                    r = !1,
                    !1
                }
            }), r) : (e('<p class="error">请至少邀请一个人</p>').insertAfter(n.find("#label-email")), !1)
        }).on("ajax:beforeSend", n + " .form-invite", 
        function(t, n, r) {
            var i = e("input.invite-email").map(function() {
                return e.trim(e(this).val())
            }).get().filter(function(e) {
                return e !== ""
            }).join(",");
            r.data += "&emails=" + encodeURIComponent(i)
        }).on("click", n + " .select-all-proj", 
        function(t) {
            t.preventDefault(),
            e(".proj-in input[type=checkbox]").prop("checked", !0)
        }).on("click", n + " .select-none-proj", 
        function(t) {
            t.preventDefault(),
            e(".proj-in input[type=checkbox]").prop("checked", !1)
        }).on("click", n + " .link-invite-message", 
        function(t) {
            t.preventDefault();
            var n = e(t.target);
            n.next(".form-item").show().end().remove()
        }).on("ajax:error", n + " .form-invite", mcw.inviteError).on("click", n + " #add-invite-item", mcw.addInviteItem).on("click", n + " .del-invite", mcw.removeInviteItem)
    }),
    e.extend(mcw, {
        removeInviteItem: function(t) {
            t.preventDefault();
            var n = e(t.target),
            r = n.closest(".invite-item"),
            i = r.siblings();
            r.fadeTo(200, 0).slideUp(200, 
            function() {
                r.remove(),
                i.length === 1 && i.eq(0).find(".del-invite").remove()
            })
        },
        addInviteItem: function(t) {
            t.preventDefault();
            var n = e(t.target),
            r = n.closest(".form-item"),
            i = r.find(".invite-item:last"),
            s = i.clone(!0),
            o = s.find("input").val("");
            s.find(".error").remove(),
            s.insertAfter(i),
            o.focus(),
            r.find(".invite-item:not(:has(.del-invite)) input").after('<a href="javascript:;" class="del-invite">删除</a>')
        },
        inviteError: function(t, n) {
            var r = e(t.currentTarget),
            i = e.parseJSON(n.responseText).errors;
            if (i && i.length) {
                var s = i[0];
                if (s.target && s.target === "emails") {
                    var o = s.emails;
                    e.each(r.find("input.invite-email"), 
                    function(t, n) {
                        var n = e(n),
                        r = e.trim(n.val()),
                        i = o.indexOf(r);
                        i >= 0 && (e('<p class="error">' + r + s.msg + "</p>").appendTo(n.parent()), o.splice(i, 1))
                    }),
                    o.length && e("#label-email").next(".error").remove().end().after('<p class="error">' + o.join("、") + s.msg + "</p>")
                }
            }
        }
    })
} (jQuery),

//我的设置 https://tower.im/members/68a6f5ea5d964ad49ee62494d0032dd1/settings/

function(e) {
    var t = "page-member-settings",
    n = "#" + t;
    e(function() {
        var t = "***********";
        e("body").on("validate", n + " #txt-password", 
        function(n, r) {
            var i = {
                valid: !0
            },
            s = e.trim(e("#txt-old-password").val());
            return s && s !== t && (r === t || !r.length) && (i = {
                valid: !1,
                errorMsg: "新密码不能为空"
            }),
            i
        }).on("focus", n + " #txt-password," + n + " #txt-old-password", 
        function(n, r) {
            var i = e(this);
            i.val() == t && i.val(""),
            i.addClass("on")
        }).on("blur", n + " #txt-password," + n + " #txt-old-password", 
        function(n, r) {
            var i = e(this);
            i.val() == "" ? i.val(t).removeClass("on") : i.addClass("on")
        }).on("validate", n + " #txt-old-password", 
        function(n, r) {
            var i = {
                valid: !0
            },
            s = e.trim(e("#txt-password").val());
            return s && s !== t && (r === t || !r.length) && (i = {
                valid: !1,
                errorMsg: "现有密码不能为空"
            }),
            i
        }).on("ajax:before", n + " .form", 
        function(t, n, r) {
            var i = e("#txt-password");
            i.val() && i.hasClass("on") ? i.attr("name", "password") : i.removeAttr("name");
            var i = e("#txt-old-password");
            i.val() && i.hasClass("on") ? i.attr("name", "old_password") : i.removeAttr("name")
        }),
        e(n + " #txt-password, " + n + " #txt-old-password").blur()
    }),
    mcw.pages[t] = {
        init: function() {
            var t = e(".link-upload", n);
            mcw.upload(t, {
                action: t.data("url"),
                multiple: !1,
                beforeUpload: function(t) {
                    e(".avatar-wrapper .loading").show()
                },
                onValidate: function(t, n) {
                    return e.inArray(n, ["jpeg", "jpg", "png"]) == -1 ? (mcw.message({
                        msg: "请选择jpg或者png文件"
                    }), !1) : !0
                },
                onSuccess: function(t, n) {
                    e(".avatar-wrapper img.avatar").attr("src", n.avatar)
                },
                onError: function(t, n) {
                    var r = "";
                    try {
                        var i = e.parseJSON(n.responseText).errors;
                        e.each(errors, 
                        function(e, t) {
                            r += t.msg + "<br/>"
                        })
                    } catch(s) {
                        r = "头像上传失败"
                    } finally {
                        mcw.message({
                            msg: r
                        })
                    }
                },
                onComplete: function(t, n) {
                    e(".avatar-wrapper .loading").hide()
                }
            })
        }
    }
} (jQuery),

//我自己 https://tower.im/members/68a6f5ea5d964ad49ee62494d0032dd1/?me=1

function(e) {
    function r() {
        var t = e("#filter-project"),
        n = t.val(),
        r = e(".box .todo").show();
        n !== "-1" && r.filter(":not([data-project-guid=" + n + "])").hide(),
        i()
    }
    function i() {
        var t = e("#box-today"),
        n = e("#box-other"),
        r = e("h5", t),
        i = e(".todo", t),
        s = e(".todo", n); ! i.length && !s.length ? (e("#boxes").hide(), e(".init-todo-empty").show()) : (e("#boxes").show(), e(".init-todo-empty").hide(), i.length ? i.filter(":visible").length ? (r.show(), e(".init-box-empty").hide(), e("#init-filter-empty").hide()) : (r.hide(), e(".init-box-empty").hide(), e("#init-filter-empty").show()) : (r.hide(), e(".init-box-empty").show(), e("#init-filter-empty").hide()))
    }
    function s() {
        var t = e(".box .todo"),
        n = e("#filter-project"),
        i = {},
        s = n.val();
        t.each(function(t, n) {
            n = e(n),
            i[n.data("project-guid")] = n.data("project-name")
        });
        var o = e('<option value="-1">所有项目</option>');
        e.each(i, 
        function(t, n) {
            var r = e('<option value="' + t + '">' + n + "</option>");
            t === s && r.attr("selected", !0),
            o = o.add(r)
        }),
        n.html(o),
        n.val(s),
        r()
    }
    function o() {
        var t = e("#box-other"),
        n = e("#box-today"),
        r = e(".todos", t),
        s = e(".todos", n),
        o = e(".todo", r),
        u = e(".todo", s),
        a = {
            revert: "invalid",
            revertDuration: 200,
            cursor: "pointer",
            handle: ".todo-content",
            helper: function(t) {
                var n = e(t.currentTarget);
                return n.css("position", "absolute"),
                n.get(0)
            },
            axis: "y",
            stop: function(t, n) {
                e(n.helper).css({
                    position: "static"
                })
            }
        },
        f = {
            activeClass: "ui-state-highlight",
            hoverClass: "ui-state-droppable",
            drop: function(t, o) {
                var u = o.draggable,
                a = e(".todo-content a", u).text(),
                f = e(".assignee", u).data("guid");
                u.css({
                    top: 0,
                    position: "static"
                });
                var l = {
                    todo_content: a,
                    assignee_guid: f,
                    due_at: moment().sod().valueOf()
                };
                u.parents(".todos").is(r) ? (n.find("h5").show().end().find(".init").hide(), u.appendTo(s)) : (u.appendTo(r), l.due_at = undefined),
                mcw.tinyLoading(e(".todo-assign-due", u)),
                e.ajax({
                    url: u.find(".todo-actions .edit").attr("href"),
                    data: l,
                    success: function(t) {
                        var n = e(t.html);
                        u.replaceWith(n),
                        mcw.highlight(e(".todo-content", n)),
                        mcw.adjustTodo(n),
                        i()
                    }
                })
            },
            activate: function(t, n) {
                e(t.target).is(n.draggable.parents(".todos")) && e(t.target).removeClass("ui-state-highlight")
            }
        };
        e(".box").on("mouseenter", ".todo", 
        function() {
            var t = e(this);
            t.hasClass("ui-draggable") || t.draggable(a)
        }),
        n.droppable(e.extend(f, {
            accept: "#box-other .todo"
        })),
        t.droppable(e.extend(f, {
            accept: "#box-today .todo"
        }))
    }
    function u() {
        function o(t, n) {
            var r = moment(e(t).find(".due").data("date") || "2999-01-01"),
            i = moment(e(n).find(".due").data("date") || "2999-01-01");
            return r.diff(i)
        }
        var t = moment().endOf("day"),
        n = e("#box-today .todolist .todos-uncompleted"),
        r = e("#box-other .todolist .todos-uncompleted");
        n.find(".todo").add(r.find(".todo")).each(function() {
            var i = e(this),
            s = i.find(".due");
            if (!s.length || !s.data("date")) {
                i.appendTo(r);
                return
            }
            var o = moment(s.data("date"));
            o.diff(t) > 0 ? i.appendTo(r) : i.appendTo(n)
        });
        var i = n.find(".todo").sort(o),
        s = r.find(".todo").sort(o);
        n.append(i),
        r.append(s)
    }
    var t = "page-member",
    n = "#" + t;
    e(function() {
        e(document).on("change", n + " #filter-project", 
        function(e) {
            r()
        }).on("todoremove todocomplete todoreopen", n, 
        function(e) {
            i()
        }).on("todoupdate", n, 
        function(t) {
            var r = e(this);
            r.find(".assignee").data("guid") !== e(n).data("guid") ? setTimeout(function() {
                r.fadeOut(function() {
                    r.remove(),
                    e(".workspace .page:last").trigger("todoremove", [r])
                })
            },
            1e3) : (u(), i())
        })
    }),
    mcw.pages[t] = {
        init: function() {
            var t = e(n);
            t.data("self") && e("#nav-me").addClass("active"),
            !t.is("[data-locked]") && t.data("self") && o(),
            s(),
            mcw.adjustTodo()
        },
        update: function(t) {
            var i = e("#box-other .todolist .todos-uncompleted"),
            s = e(n).data("guid");
            if (!t.member_todos) return;
            var o = [],
            a = !1;
            t.member_todos.created && t.member_todos.created.length && (e.each(t.member_todos.created, 
            function(t, n) {
                var r = e(n).hide(),
                s = e("#boxes").find(".todo[data-guid=" + r.data("guid") + "]");
                s.length ? s.replaceWith(r) : i.append(r),
                mcw.adjustTodo(r),
                o.push(r.find(".todo-content"))
            }), a = !0),
            t.member_todos.deleted && t.member_todos.deleted.length && e.each(t.member_todos.deleted, 
            function(t, n) {
                e("#boxes").find(".todo[data-guid=" + n + "]").remove()
            }),
            t.member_todos.updated && t.member_todos.updated.length && (e.each(t.member_todos.updated, 
            function(t, n) {
                var r = e(n).hide(),
                u = r.find(".assignee").data("guid"),
                a = e("#boxes").find(".todo[data-guid=" + r.data("guid") + "]");
                if (u != s) {
                    a.remove();
                    return
                }
                a.length ? a.before(r).remove() : i.append(r),
                mcw.adjustTodo(r),
                o.push(r.find(".todo-content"))
            }), a = !0),
            a && (u(), r()),
            e(o).each(function() {
                mcw.highlight(e(this))
            })
        }
    }
} (jQuery),

//团队页 https://tower.im/members/

function(e) {
    var t = "page-members",
    n = "#" + t;
    e(function() {
        e(".wrapper").on("click", n + " .member.new.cannot", 
        function(e) {
            return mcw.message({
                msg: "只有管理员才能邀请新成员。<br/>去找其他管理员为你授权或者帮你邀请吧。"
            }),
            !1
        })
    }),
    mcw.pages[t] = {
        init: function() {
            e("#nav-members").addClass("active")
        }
    }
} (jQuery),

//讨论内容页 https://tower.im/projects/7f19cd0e6d2446f2a8eaea9520abc941/messages/bf59c68531624db8b4dceb861818fdf4/

function(e) {
    function r(t, n) {
        var r = e(n.html),
        i = e(t.target).closest(".message");
        i.hide(),
        r.insertAfter(i),
        mcw.editor(r.find("textarea"))
    }
    function i(t, n) {
        var r = e(n.html),
        i = e(t.target).closest(".message-form.edit"),
        s = i.prev(),
        o = i.find(".editor").data("editor");
        o.destroyEditor(),
        s.replaceWith(r),
        mcw.adjustDate(r),
        mcw.adjustPermission(r),
        i.remove()
    }
    function s(t) {
        var n = e(this).closest(".form"),
        r = n.find(".editor").data("editor");
        r.destroyEditor(),
        e(t.currentTarget).parents(".message-form.edit").hide().prev().show().end().remove()
    }
    function o() {
        mcw.globalLoading("正在删除讨论...")
    }
    function u() {
        mcw.globalLoading("hide")
    }
    var t = "page-message",
    n = "#" + t;
    e(function() {
        e("body").on("ajax:success", n + " .message-actions .edit", r).on("click", n + " #link-cancel-post", s).on("ajax:success", n + " .form-edit-message", i).on("ajax:beforeSend", n + " .message-actions .del", o).on("ajax:complete", n + " .message-actions .del", u)
    }),
    mcw.pages[t] = {
        init: function() {
            mcw.adjustCCList(),
            mcw.adjustAuthor()
        },
        update: function(t) {
            if (!t.message) return;
            if (t.message.updated) {
                var n = e(".workspace .page:last");
                if (n.is("[data-deleted]")) return mcw.stack({
                    url: location.href,
                    nocache: !0
                }),
                !1;
                var r = e(t.message.updated),
                i = e(".message");
                r.toggle(i.is(":visible")),
                i.replaceWith(r),
                mcw.adjustDate(r),
                mcw.adjustPermission(r)
            }
            if (t.message.deleted) return mcw.stack({
                url: location.href,
                nocache: !0
            }),
            !1
        }
    }
} (jQuery),

//通知设置 https://tower.im/members/68a6f5ea5d964ad49ee62494d0032dd1/notification_settings/

function(e) {
    var t = "page-notification-settings",
    n = "#" + t;
    e(function() {
        e(".wrapper").on("click", n + " .option input:radio", 
        function(t) {
            var n = e(this),
            r = n.closest(".option");
            if (r.hasClass("active")) return;
            r.addClass("active").siblings(".option").removeClass("active"),
            r.hasClass("option-on") ? r.find(".choose-project").removeClass("hide").end().find(".project-list input:checkbox").attr("checked", "checked") : r.siblings(".option").find(".select-shortcut, .project-list").addClass("hide").end().find(".choose-project").removeClass("hide")
        }).on("click", n + " .choose-project a", 
        function(t) {
            t.preventDefault();
            var n = e(this).closest(".choose-project").addClass("hide");
            optEl = n.closest(".option"),
            optEl.addClass("active").siblings(".option").removeClass("active"),
            optEl.find("input:radio").attr("checked", "checked").end().find(".select-shortcut, .project-list").removeClass("hide").end().find(".project-list input:checkbox").attr("checked", "checked")
        }).on("ajax:before", n + " .form", 
        function(t) {
            var n = e("#radio-d18n-on").is(":checked");
            n && !mcw.d18n.permitted() && mcw.d18n.requestPermission()
        }).on("ajax:success", n + " .form", 
        function(t) {
            var n = e("#radio-d18n-on").is(":checked");
            e("#d18n-enabled").val(n ? "true": "false")
        }).on("click", n + " .select-all", 
        function(t) {
            t.preventDefault(),
            e(this).closest(".option").find(".project-list input:checkbox").attr("checked", "checked")
        }).on("click", n + " .select-none", 
        function(t) {
            t.preventDefault(),
            e(this).closest(".option").find(".project-list input:checkbox").removeAttr("checked")
        })
    })
} (jQuery),

//通知 https://tower.im/teams/ca80bfd1700e46798581f20021c588cb/notifications/

function(e) {
    var t = "page-notifications";
    page = "#" + t,
    e(function() {
        e(".wrapper").on("click", page + " .notice.unread .link, .notice.unread .commnets-count", 
        function(t) {
            var n = e(this).closest(".notice").removeClass("unread"),
            r = n.data("notification-guid");
            mcw.readNotification(r)
        })
    }),
    mcw.pages[t] = {
        init: function() {
            mcw.scrollLoad(page, 
            function() {
                return e.ajax({
                    url: e(page).data("url"),
                    dataType: "html",
                    type: "get",
                    data: {
                        till: e(".notice:last").data("created-at")
                    },
                    success: function(t) {
                        t && (e(".notifications").append(t), mcw.adjustDate())
                    }
                })
            })
        },
        update: function(t) {
            if (!t.notifications) return;
            var n = e(".notifications");
            t.notifications.created && t.notifications.created.length && e.each(t.notifications.created, 
            function(t, r) {
                n.find("[data-topic-guid=" + r.guid + "]").remove();
                var i = e(r.html).prependTo(n);
                mcw.adjustDate(i)
            }),
            t.notifications.updated && t.notifications.updated.length && e.each(t.notifications.updated, 
            function(e, t) {
                n.find("[data-notification-guid=" + t + "]").removeClass("unread")
            })
        }
    }
} (jQuery),

//全部讨论 https://tower.im/projects/7f19cd0e6d2446f2a8eaea9520abc941/topics/

function(e) {
    var t = "page-topics",
    n = "#" + t;
    e(function() {
        e(".wrapper").on("click", n + " .editor-placeholder", 
        function(t) {
            t.preventDefault(),
            e(this).hide();
            var n = e(".form-new-discussion").show(),
            r = n.find(".editor");
            n.find("#txt-title").focus(),
            r.length || mcw.editor(e("#txt-content")),
            e(".init.init-discussion").hide()
        }).on("click", n + " #link-cancel-post", 
        function(t) {
            t.preventDefault();
            var n = e(".form-new-discussion"),
            r = n.find(".editor");
            if (r.length) {
                var i = r.data("editor");
                i.destroyEditor()
            }
            n.hide(),
            e(".init.init-discussion, .editor-placeholder").show()
        }).on("ajax:success", n + " .form-new-discussion", 
        function(t, n) {
            e(".init.init-discussion").remove(),
            e("#link-cancel-post").click(),
            e("#txt-title, txt-content").val("");
            var r = e(".messages"),
            i = e(n.html).hide().prependTo(r).fadeIn();
            r.offset().top < e(document).scrollTop() && mcw.scrollTo(".editor-wrapper"),
            mcw.adjustDate(i)
        })
    }),
    mcw.pages[t] = {
        init: function() {
            mcw.scrollLoad(n, 
            function() {
                return e.ajax({
                    url: location.pathname,
                    dataType: "html",
                    type: "get",
                    data: {
                        till: e(".message:last").data("last-comment-at")
                    },
                    success: function(t) {
                        t && (e(".messages").append(t), mcw.adjustDate())
                    }
                })
            })
        }
    }
} (jQuery),

//成员管理 https://tower.im/members/7d1d80ad62614d64b789a8c196b01835/settings/

function(e) {
    var t = "page-member",
    n = "#" + t;
    e(function() {
        e("body").on("ajax:success", n + " #link-upgrade", 
        function(t) {
            e(".status-admin").removeClass("hide"),
            e(".status-normal").addClass("hide")
        }).on("ajax:success", n + " #link-downgrade", 
        function(t) {
            e(".status-admin").addClass("hide"),
            e(".status-normal").removeClass("hide")
        }).on("ajax:beforeSend", n + " #link-remove-member", 
        function(e) {
            mcw.globalLoading("正在移除...")
        }).on("ajax:success", n + " #link-remove-member", 
        function(e) {
            mcw.globalLoading("hide")
        }).on("ajax:error", n + " #link-remove-member", 
        function(e) {
            mcw.globalLoading("hide")
        })
    })
} (jQuery),

//回顾 https://tower.im/teams/ca80bfd1700e46798581f20021c588cb/progress/

function(e) {
    function r() {
        var t = e(".progress-day.today"),
        n = e(".progress-day.yesterday"),
        r = moment().format("YYYY-MM-DD"),
        i = moment().add("d", -1).format("YYYY-MM-DD");
        if (t.data("date") != r) {
            var s = moment(t.data("date"), "YYYY-MM-DD");
            t.find("h4").empty().removeClass("today").append("<span class='date'>" + s.format("M/D") + "</span>").append("<span class='day'>" + moment.weekdays[s.day()] + "</span>")
        }
        if (n.data("date") != i) {
            var s = moment(n.data("date"), "YYYY-MM-DD");
            n.find("h4").empty().removeClass("yesterday").append("<span class='date'>" + s.format("M/D") + "</span>").append("<span class='day'>" + moment.weekdays[s.day()] + "</span>")
        }
        e(".progress-day[data-date=" + r + "]").addClass("today").find("h4:first").html("今"),
        e(".progress-day[data-date=" + i + "]").addClass("yesterday").find("h4:first").html("昨")
    }
    var t = "page-progress",
    n = "#" + t;
    e(function() {
        e("body").on("change", n + " #select-member", 
        function(t) {
            var n = e(this).val(),
            r;
            "0" == n ? r = location.pathname: r = location.pathname + "?by_member=" + n,
            mcw.stack({
                url: r,
                root: !0,
                bare: !0,
                nocache: !0
            })
        })
    }),
    mcw.pages[t] = {
        init: function() {
            e("#nav-progress").addClass("active"),
            r(),
            mcw.scrollLoad(n, 
            function(t) {
                return e.ajax({
                    url: location.pathname,
                    dataType: "html",
                    data: {
                        till: e(".progress-day:last").attr("data-date"),
                        by_member: e("#select-member").val()
                    },
                    success: function(e) {
                        e && (t.before(e), r())
                    }
                })
            })
        },
        update: function(t) {
            if (!t.progress) return;
            var n = [];
            t.progress.created && t.progress.created.length && (e.each(t.progress.created, 
            function(t, r) {
                var i = e(r.html),
                s = moment(i.find(".datetime").text(), "YYYY-MM-DD HH:mm: "),
                o = e(".progress-day[data-date=" + s.format("YYYY-MM-DD") + "]");
                o.length || (o = mcw.template("tpl-progress-day", {
                    date: s.format("YYYY-MM-DD"),
                    dateStr: s.format("M/D"),
                    dayStr: moment.weekdays[s.day()]
                }).insertAfter("#select-member"));
                var u = o.find(".progress-project:first");
                if (!u.length || u.data("guid") != r.project.guid) u = mcw.template("tpl-progress-project", {
                    guid: r.project.guid,
                    name: r.project.name
                }).insertAfter(o.find("h4"));
                i.insertAfter(u.find("h5")),
                n.push(i)
            }), r()),
            e(n).each(function() {
                mcw.highlight(e(this))
            })
        }
    }
} (jQuery),

//创建新项目 https://tower.im/teams/ca80bfd1700e46798581f20021c588cb/projects/new/

function(e) {
    var t = "page-new-project",
    n = "#" + t;
    e(function() {
        mcw.preloadImages(["/assets/icon-check-e5b477cb7a924487bf783a0e8a374a21.png"]),
        e("body").on("ajax:beforeSend", n + " form.form", 
        function(t, n, r) {
            membersGuid = e(".member.selected").map(function() {
                return e(this).data("guid")
            }).get(),
            invitations = e(".member.invited.selected").map(function() {
                return e(this).data("guid")
            }).get(),
            emails = e("input.invite-email").map(function() {
                return e.trim(e(this).val())
            }).get().filter(function(e) {
                return e !== ""
            }).join(","),
            r.data += "&members=" + membersGuid.join(",") + "&invitations=" + invitations.join(",") + "&emails=" + encodeURIComponent(emails)
        }).on("click", n + " .member", 
        function(t) {
            var n = e(t.currentTarget);
            n.toggleClass("selected")
        }).on("submit", n + " form.form", 
        function(t) {
            var n = e(this),
            r = !0,
            i = e.grep(e("input.invite-email"), 
            function(t, n) {
                return e.trim(e(t).val()) !== ""
            });
            return e("input.invite-email:first").closest(".form-item").find("p.error").remove(),
            e.each(i, 
            function(n, i) {
                var i = e(i),
                s = i.val(),
                o = e.trim(s);
                if (!mcw.validate.email(o).valid) {
                    var u = s.indexOf(o),
                    a = o + " 不是一个正确的邮箱地址";
                    return mcw.selectText(t.currentTarget, u, o.length),
                    e('<p class="error">' + a + "</p>").appendTo(i.parent()),
                    r = !1,
                    !1
                }
            }),
            r
        }).on("click", n + " .link-show-invite", 
        function(t) {
            t.preventDefault(),
            e(t.target).hide().next().show()
        }).on("ajax:error", n + " form.form", mcw.inviteError).on("click", n + " #add-invite-item", mcw.addInviteItem).on("click", n + " .del-invite", mcw.removeInviteItem)
    })
} (jQuery),

//项目 https://tower.im/projects/7f19cd0e6d2446f2a8eaea9520abc941/settings/
function(e) {
    var t = "page-project-settings",
    n = "#" + t;
    e(function() {
        e(".wrapper").on("ajax:success", n + " form#form-info", 
        function(t, n) {
            e(".project-info").find(".name a").text(n.name).end().find(".desc").text(n.desc)
        }).on("ajax:beforeSend", n + " #btn-archive-project", 
        function(e) {
            mcw.globalLoading("正在归档项目..."),
            mcw.clearPageCache()
        }).on("ajax:beforeSend", n + " #btn-unarchive-project", 
        function(e) {
            mcw.globalLoading("正在激活项目..."),
            mcw.clearPageCache()
        }).on("click", n + " #btn-unarchive-denied", 
        function(t) {
            var n = e("#reach-max-msg").html();
            return mcw.message({
                msg: n,
                width: 550
            }),
            !1
        }).on("ajax:success", n + " #btn-archive-project", 
        function(e) {
            mcw.globalLoading("hide")
        }).on("ajax:success", n + " #btn-unarchive-project", 
        function(e) {
            mcw.globalLoading("hide")
        }).on("click", n + " #btn-del-project", 
        function(e) {
            e.preventDefault(),
            mcw.dialog({
                el: mcw.template("tpl-del-project"),
                modal: !0
            })
        }).on("click", n + " #btn-cancel-del", 
        function(e) {
            mcw.dialog("hide")
        }).on("click", n + " #btn-exec-del", 
        function(t) {
            var n = e(t.currentTarget),
            r = n.data("url");
            e.ajax({
                url: r,
                type: "post",
                dataType: "json",
                beforeSend: function() {
                    mcw.dialog("hide"),
                    mcw.globalLoading("正在删除项目...")
                },
                success: function(e) {
                    e.success && (mcw.globalLoading("hide"), mcw.stack({
                        url: e.target_url,
                        replace: !1,
                        root: !0,
                        restorePosition: !1
                    }))
                }
            })
        }).on("keyup", n + " #del-project-text", 
        function(t) {
            var n = e(t.currentTarget);
            n.val() === "DELETE" ? e("#btn-exec-del").prop("disabled", !1) : e("#btn-exec-del").prop("disabled", !0)
        })
    }),
    mcw.pages[t] = {
        init: function(t) {
            t.is("[data-archived], [data-locked], [data-deleted]") && e("#project-name, #project-desc, #btn-save-settings").attr("disabled", "disabled")
        }
    }
} (jQuery),

//项目成员管理 https://tower.im/projects/06153e5a411c416c8981e3879466f087/members/

function(e) {
    var t = "page-project-members",
    n = "#" + t;
    e(function() {
        mcw.preloadImages(["/assets/icon-check-e5b477cb7a924487bf783a0e8a374a21.png"]),
        e("body").on("click", n + " .member", 
        function(t) {
            if (e("#btn-save-members").is(":disabled")) return;
            var n = e(t.currentTarget);
            n.toggleClass("selected")
        }).on("ajax:beforeSend", n + " form#form-members", 
        function(t, n, r) {
            membersGuid = e(".member.selected").map(function() {
                return e(this).data("guid")
            }).get(),
            invitations = e(".member.invited.selected").map(function() {
                return e(this).data("guid")
            }).get(),
            emails = e("input.invite-email").map(function() {
                return e.trim(e(this).val())
            }).get().filter(function(e) {
                return e !== ""
            }).join(","),
            r.data += "&members=" + membersGuid.join(",") + "&invitations=" + invitations.join(",") + "&emails=" + encodeURIComponent(emails)
        }).on("ajax:success", n + " form#form-members", 
        function(t, n) {
            var r = e("button[type=submit]", t.target).data("project-guid");
            r && mcw.members && delete mcw.members[r],
            e(".invite-item:first").find(".del-invite").remove().end().find("input").val("").end().siblings(".invite-item").remove();
            if (n.invitations) {
                var i = e("ul.members");
                e.each(n.invitations, 
                function(e, t) {
                    t.nickname = t.email,
                    mcw.template("tpl-invited-member", t).hide().appendTo(i).fadeIn()
                })
            }
        }).on("submit", n + " .form#form-members", 
        function(t) {
            var n = e(this),
            r = !0,
            i = e.grep(e("input.invite-email"), 
            function(t, n) {
                return e.trim(e(t).val()) !== ""
            });
            return e("input.invite-email:first").closest(".form-item").find("p.error").remove(),
            e.each(i, 
            function(n, i) {
                var i = e(i),
                s = i.val(),
                o = e.trim(s);
                if (!mcw.validate.email(o).valid) {
                    var u = s.indexOf(o),
                    a = o + " 不是一个正确的邮箱地址";
                    return mcw.selectText(t.currentTarget, u, o.length),
                    e('<p class="error">' + a + "</p>").appendTo(i.parent()),
                    r = !1,
                    !1
                }
            }),
            r
        }).on("click", n + " .link-show-invite", 
        function(t) {
            t.preventDefault(),
            e(t.target).hide().next().show()
        }).on("ajax:error", n + " form#form-members", mcw.inviteError).on("click", n + " #add-invite-item", mcw.addInviteItem).on("click", n + " .del-invite", mcw.removeInviteItem)
    }),
    mcw.pages[t] = {
        init: function(t) {
            t.is("[data-archived], [data-locked], [data-deleted]") && e("#btn-save-members").attr("disabled", "disabled")
        }
    }
} (jQuery),

//项目内容页 https://tower.im/projects/06153e5a411c416c8981e3879466f087/

function(e) {
    var t = "page-project",
    n = "#" + t;
    e(function() {
        e(".wrapper").on("click", n + " div.todolists-completed .show-all a", 
        function(t) {
            t.preventDefault(),
            e(t.target).parent().next("span.all").show().end().remove()
        }).on("click.file", n + " .file .link-cancel", 
        function(t) {
            t.preventDefault();
            var n = e(t.currentTarget).parents(".file:first"),
            r = n.attr("fileid");
            r && n.hasClass("uploading") && uploader.cancel(r),
            n.removeClass("uploading").fadeOut(function() {
                n.siblings().length || e("div.init").show(),
                n.remove()
            })
        }).on("click", n + " .btn-new-discussion", 
        function(t) {
            t.preventDefault();
            var n = e(".form-new-discussion").show(),
            r = n.find(".editor");
            n.find("#txt-title").focus(),
            r.length || mcw.editor(e("#txt-content")),
            e(".init.init-discussion").hide()
        }).on("click", n + " #link-cancel-post", 
        function(t) {
            t.preventDefault();
            var n = e(".form-new-discussion"),
            r = n.find(".editor");
            if (r.length) {
                var i = r.data("editor");
                i.destroyEditor()
            }
            n.hide(),
            e(".init.init-discussion").show()
        }).on("ajax:success", n + " .form-new-discussion", 
        function(t, n) {
            e("#link-cancel-post").click(),
            e("#txt-title, txt-content").val("");
            var r = e(".messages");
            messageEl = e(n.html).hide().prependTo(r).fadeIn();
            var i = e(".link-more-topics");
            i.length && i.text(i.text().replace(/\d+/, 
            function(e) {
                return e * 1 + 1
            })),
            mcw.adjustDate(messageEl),
            e(".init.init-discussion").hide(),
            r.find(".message:gt(2)").hide(),
            r.find(".message:lt(3)").show()
        }).on("filedelete", n + " .file", 
        function(t, n) {
            var r = e(".link-more-files"),
            i = r.text().replace(/\d+/, 
            function(e) {
                return e * 1 - 1
            });
            r.text(i),
            n.siblings(".file").length || r.hide();
            var s = n.closest(".file-list");
            n.remove(),
            s.find(".file:gt(4)").hide(),
            s.find(".file:lt(5)").show()
        })
    }),
    mcw.pages[t] = {
        init: function() {
            mcw.initTodoFilter(),
            mcw.sortTodos(),
            mcw.sortTodolists(),
            mcw.initUpload({
                countEl: e(".link-more-files"),
                beforeUpload: function() {
                    var t = e(".file-list");
                    t.find(".file:gt(4)").hide(),
                    t.find(".file:lt(5)").show()
                }
            }),
            mcw.me.admin || e(".link-admin").remove(),
            mcw.adjustCCList(),
            mcw.adjustTodo(),
            mcw.adjustTodoFilter(),
            mcw.adjustFile()
        }
    }
} (jQuery),

//修改密码

function(e) {
    e(function() {
        var t = e("#page-reset-password");
        if (t.length < 1) return;
        t.on("ajax:success", "form.form", 
        function(t, n) {
            var r = e(".center-box .bd").empty();
            mcw.template("template-success").appendTo(r)
        })
    })
} (jQuery),

//搜索结果 https://tower.im/search/?keyword=2

function(e) {
    var t = "page-search-result",
    n = "#" + t;
    e.expr[":"].icontains = function(e, t, n, r) {
        return (e.textContent || e.innerText || jQuery(e).text() || "").toLowerCase().indexOf(n[3].toLowerCase()) >= 0
    },
    e(function() {}),
    mcw.pages[t] = {
        init: function() {
            var t = e("#keyword").val(),
            n = new RegExp(t, "ig");
            e(".results p, .results a, .results span").filter(':icontains("' + t + '")').each(function() {
                var t = e(this);
                if (this.childNodes.length === 1 && this.childNodes[0].nodeType === 3) {
                    var r = t.text();
                    t.html(r.replace(n, 
                    function(e) {
                        return '<span class="match">' + e + "</span>"
                    }))
                }
            });
            var r = e(".sheet-active select.category"),
            i = e(".results [data-category]"),
            s = e(".results .empty");
            r.on("change", 
            function(e) {
                i.filter(":hidden").show();
                var t = r.val();
                "all" != t && i.not('[data-category="' + t + '"]').hide(),
                i.filter(":visible").length ? s.hide() : s.show()
            })
        }
    }
} (jQuery),

//付费 https://tower.im/teams/ca80bfd1700e46798581f20021c588cb/settings/

function(e) {
    var t = "page-team-settings",
    n = "#" + t;
    e(function() {
        e("body").on("click", n + " .team-name a.edit", 
        function(t) {
            t.preventDefault();
            var n = e(this).parents("h3:first").hide().find(".name").text(),
            r = e("form.form-team").show();
            r.find("input").val(n).focus()
        }).on("ajax:success", n + " .form-team", 
        function(t, n) {
            var r = e(this),
            i = n.name;
            r.find("input").val("").end().hide().siblings("h3").find(".name").text(i).end().show()
        }).on("keydown", ".form-team", 
        function(t) {
            t.keyCode === 27 && (t.preventDefault(), e(t.currentTarget).find(".btn-cancel").click())
        }).on("click", n + " .team-name .btn-cancel", 
        function(t) {
            e(this).parents("form:first").hide().find("input").val("").end().siblings("h3").show()
        }).on("click", n + " #btn-del-team", 
        function(e) {
            e.preventDefault(),
            mcw.dialog({
                el: mcw.template("tpl-del-team"),
                width: 660,
                modal: !0
            })
        }).on("click", n + " #btn-cancel-del", 
        function(e) {
            mcw.dialog("hide")
        }).on("click", n + " #btn-exec-del", 
        function(t) {
            var n = e(t.currentTarget),
            r = n.data("url");
            e.ajax({
                url: r,
                type: "post",
                dataType: "json",
                beforeSend: function() {
                    mcw.dialog("hide"),
                    mcw.globalLoading("正在删除团队...")
                },
                success: function(e) {
                    e.success && (mcw.globalLoading("hide"), location.href = e.target_url)
                }
            })
        }).on("keyup", n + " #del-team-text", 
        function(t) {
            var n = e(t.currentTarget);
            n.val() === "DELETE" ? e("#btn-exec-del").prop("disabled", !1) : e("#btn-exec-del").prop("disabled", !0)
        }).on("ajax:beforeSend", n + " .form-trans-account", 
        function(t) {
            var n = e("button[type=submit]", this);
            mcw.tinyLoading(n)
        }).on("ajax:success", n + " .form-trans-account", 
        function(e, t) {
            t.success && (location.href = t.next_url)
        }).on("ajax:complete", n + " .form-trans-account", 
        function(e, t) {
            mcw.tinyLoading(btn, !1)
        })
    })
} (jQuery),

//项目页事件 https://tower.im/teams/ca80bfd1700e46798581f20021c588cb/

function(e) {
    function r(t) {
        t.preventDefault(),
        t.stopPropagation();
        var r = e(t.currentTarget);
        if (r.hasClass("visible")) {
            e(document).trigger("click.badge");
            return
        }
        e(document).trigger("click.badge");
        var i = r.parent(".folder"),
        s = i.attr("class"),
        o = s.match(/c\d+/)[0],
        u = s.match(/i\d+/)[0],
        a = r.offset(),
        f = e(n).offset(),
        l = mcw.template("tpl-badge", {});
        r.addClass("visible"),
        l.find("li." + o).addClass("selected").end().find(".icons li").addClass(o).filter("." + u).addClass("selected"),
        l.appendTo(n).css({
            top: a.top - f.top + 18,
            left: a.left - f.left - l.width() / 2 - 23
        }),
        e(document).one("click.badge", 
        function(t) {
            e(".badge-edit.visible").removeClass("visible"),
            e(".badge-settings").remove(),
            e(document).unbind("keyup.badge")
        }).bind("keyup.badge", 
        function(t) {
            t.keyCode == 27 && (t.preventDefault(), e(document).trigger("click.badge"))
        })
    }
    function i(t) {
        t.preventDefault(),
        t.stopPropagation();
        var n = e(t.currentTarget);
        if (n.hasClass("selected")) return;
        var r = n.attr("class");
        n.siblings(".selected").removeClass("selected").end().addClass("selected"),
        e(".badge-settings .icons li").each(function() {
            var t = e(this).attr("class").replace(/c\d+/, r);
            e(this).attr("class", t)
        });
        var i = e(".badge-edit.visible").parent(".folder");
        i.attr("class", i.attr("class").replace(/c\d+/, r)),
        o(i)
    }
    function s(t) {
        t.preventDefault(),
        t.stopPropagation();
        var n = e(t.currentTarget);
        if (n.hasClass("selected")) return;
        var r = n.attr("class").match(/i\d+/)[0];
        n.siblings(".selected").removeClass("selected").end().addClass("selected");
        var i = e(".badge-edit.visible").parent(".folder");
        i.attr("class", i.attr("class").replace(/i\d+/, r)),
        o(i)
    }
    function o(t) {
        var n = t.attr("href") + "/badge",
        r = t.attr("class").match(/c(\d+)/)[1],
        i = t.attr("class").match(/i(\d+)/)[1];
        e.ajax({
            url: n,
            type: "post",
            dataType: "json",
            data: {
                color_id: r - 1,
                icon_id: i - 1
            },
            success: function(e) { ! e.success
            }
        })
    }
    var t = "page-team-show",
    n = "#" + t;
    e(function() {
        mcw.preloadImages(["/assets/icon-info-f6c72fc53772306ae1b88ece8f1199ad.png", "/assets/project-badge-settings-bg-abdfe0f433044519c1e382f9087485f0.png"]),
        e("body").on("click", n + " .denied", 
        function(e) {
            return mcw.message({
                msg: '只有管理员能够创建项目。<br/>去找<a href="/members/">其他管理员</a>为你授权或者帮你创建吧。'
            }),
            !1
        }).on("click", n + " .reach-max:not(.denied)", 
        function(t) {
            var n = e(t.target),
            r = e("#reach-max-msg").html();
            return mcw.message({
                msg: r,
                width: 550
            }),
            !1
        }).on("click", n + " .badge-edit", r).on("click", n + " .color-sets li", i).on("click", n + " .icons li", s).on("click", n + " .badge-settings", 
        function(e) {
            e.preventDefault(),
            e.stopPropagation()
        }).on("ajax:success", n + " .resend-email-verify", 
        function(e, t) {
            t.success ? mcw.message({
                msg: "验证邮件发送成功，请注意查收"
            }) : mcw.message({
                msg: t.msg
            })
        })
    }),
    mcw.pages[t] = {
        init: function() {
            e("#nav-project").addClass("active")
        }
    }
} (jQuery),

//任务内容页 https://tower.im/projects/06153e5a411c416c8981e3879466f087/todos/fe0f993315494b99802cbb124ae6a318/

function(e) {
    var t = "page-todo",
    n = "#" + t;
    e(function() {}),
    mcw.pages[t] = {
        init: function() {
            mcw.adjustTodo(),
            mcw.adjustCCList(),
            mcw.adjustAuthor()
        },
        update: function(t) {
            if (!t.todo) return;
            if (t.todo.updated) {
                var n = e(".workspace .page:last");
                if (n.is("[data-deleted]")) return mcw.stack({
                    url: location.href,
                    nocache: !0
                }),
                !1;
                var r = e(t.todo.updated),
                i = e(".todo");
                r.toggle(i.is(":visible")),
                i.replaceWith(r),
                mcw.adjustDate(r)
            }
            if (t.todo.deleted) return mcw.stack({
                url: location.href,
                nocache: !0
            }),
            !1
        }
    }
} (jQuery),

//单个任务列表 https://tower.im/projects/06153e5a411c416c8981e3879466f087/lists/372ebca953f449a18de01b4a0813a4bd/show/

function(e) {
    var t = "page-todolist",
    n = "#" + t;
    e(function() {}),
    mcw.pages[t] = {
        init: function(t) {
            mcw.initTodoFilter(),
            mcw.sortTodos(),
            mcw.adjustTodo(),
            mcw.adjustTodoFilter(),
            t.is("[data-archived], [data-locked], [data-deleted]") && e(".todolist-stick-checkbox").attr("disabled", "disabled");
            var n = e("#tpl-todos-completed");
            n.length && (e(".todolist .todos-completed").replaceWith(mcw.template("tpl-todos-completed")), n.remove())
        },
        update: function(t) {
            var n = e(".todolist");
            if (!t.todolist) return;
            t.todolist.deleted && mcw.stack({
                url: location.href,
                nocache: !0,
                replace: !0
            });
            if (t.todolist.updated) {
                var r = t.todolist.updated;
                r.name && n.find(".title h4 a").text(r.name),
                r.position && (n.data("sort", r.position), needResort = !0)
            }
        }
    }
} (jQuery),

//所有任务 https://tower.im/projects/06153e5a411c416c8981e3879466f087/todos/

function(e) {
    var t = "page-todolists",
    n = "#" + t;
    e(function() {}),
    mcw.pages[t] = {
        init: function() {
            mcw.initTodoFilter(),
            mcw.sortTodos(),
            mcw.sortTodolists(),
            mcw.adjustTodo(),
            mcw.adjustTodoFilter()
        }
    }
} (jQuery),

//所有完成任务 https://tower.im/projects/06153e5a411c416c8981e3879466f087/todos/completed/

function(e) {
    var t = "page-completed-todos",
    n = "#" + t;
    e(function() {
        e("body").on("change", n + " #select-member", 
        function(t) {
            location.href = location.pathname + "?by_member=" + e(this).val()
        })
    }),
    mcw.pages[t] = {
        init: function() {
            mcw.scrollLoad(n, 
            function(t) {
                return e.ajax({
                    url: location.pathname,
                    dataType: "html",
                    data: {
                        till: e(".day:last").attr("data-date"),
                        by_member: e("#select-member").val()
                    },
                    success: function(e) {
                        e && t.before(e)
                    }
                })
            })
        }
    }
} (jQuery),

//个人已完成的任务 https://tower.im/members/68a6f5ea5d964ad49ee62494d0032dd1/todos/completed/

function(e) {
    var t = "page-member-completed-todos",
    n = "#" + t;
    e(function() {}),
    mcw.pages[t] = {
        init: function() {
            mcw.scrollLoad(n, 
            function(t) {
                return e.ajax({
                    url: location.pathname,
                    dataType: "html",
                    data: {
                        till: e(".day:last").attr("data-date")
                    },
                    success: function(e) {
                        e && t.before(e)
                    }
                })
            })
        }
    }
} (jQuery),

//所有文件 https://tower.im/projects/06153e5a411c416c8981e3879466f087/attachments/

function(e) {
    var t = "page-attachments",
    n = "#" + t;
    e(function() {
        e(document).on("filedelete", n + " .file", 
        function(t, n) {
            n.siblings().length || n.closest(".day").hide(),
            e(".day:visible").length || e("div.init-file").show()
        })
    }),
    mcw.pages[t] = {
        init: function(t) {
            mcw.adjustFile();
            var n = e(".day:first");
            if (!n.length) {
                var r = e("div.init-file");
                r.hide(),
                n = mcw.template("tpl-today", {
                    date: moment().format("YYYY-MM-DD")
                }).insertBefore(r).hide()
            } else ! moment(n.data("date")).diff(moment().sod()) || (n = mcw.template("tpl-today", {
                date: moment().format("YYYY-MM-DD")
            }).insertBefore(n).hide());
            t.is("[data-archived], [data-locked], [data-deleted]") ? t.find(".btn-add-files").remove() : mcw.initUpload({
                btn: e(".btn-add-files"),
                container: n.find(".file-list"),
                beforeUpload: function() {
                    n.show()
                },
                onCancel: function(t) {
                    t.siblings().length || t.closest(".day").hide(),
                    e(".day:visible").length || e("div.init-file").show()
                }
            }),
            mcw.scrollLoad(t, 
            function(t) {
                return e.ajax({
                    url: location.pathname,
                    type: "get",
                    dataType: "html",
                    data: {
                        till: e(".day:last").attr("data-date")
                    },
                    success: function(e) {
                        e && t.before(e)
                    }
                })
            })
        }
    }
} (jQuery),

//回收站中该文件 https://tower.im/projects/06153e5a411c416c8981e3879466f087/uploads/e8ad5ec92db14206880481081a79719a/

function(e) {
    var t = "page-file",
    n = "#" + t;
    e(function() {
        e("body").on("ajax:beforeSend", n + " .file-actions .del", 
        function(e) {
            mcw.globalLoading("正在删除文件...")
        }).on("ajax:success", n + " .file-actions .del", 
        function(e) {
            mcw.globalLoading("hide")
        })
    }),
    mcw.pages[t] = {
        init: function() {
            mcw.adjustCCList(),
            mcw.adjustAuthor(),
            mcw.adjustFile()
        },
        update: function(t) {
            if (!t.upload) return;
            if (t.upload.updated) {
                var n = e(".workspace .page:last");
                if (n.is("[data-deleted]")) return mcw.stack({
                    url: location.href,
                    nocache: !0
                }),
                !1;
                var r = e(t.upload.updated),
                i = e(".upload");
                r.toggle(i.is(":visible")),
                i.replaceWith(r),
                mcw.adjustDate(r),
                mcw.adjustPermission(r)
            }
            if (t.upload.deleted) return mcw.stack({
                url: location.href,
                nocache: !0
            }),
            !1
        }
    }
} (jQuery),


function(e) {
    var t = "page-folders",
    n = "#" + t;
    e(function() {}),
    mcw.pages[t] = {
        init: function() {}
    }
} (jQuery),

//文件标记 https://tower.im/projects/06153e5a411c416c8981e3879466f087/dirs/aad2fa4e622540349199e288e0af69c9/

function(e) {
    var t = "page-folder",
    n = "#" + t;
    e(function() {}),
    mcw.pages[t] = {
        init: function(e) {
            mcw.adjustFile()
        }
    }
} (jQuery),

//团队选择 https://tower.im/launchpad

function(e) {
    var t = "page-launchpad",
    n = "#" + t;
    e(function() {
        e("body").on("click", n + " #btn-new-team", 
        function(e) {
            e.preventDefault(),
            mcw.dialog({
                el: mcw.template("tpl-new-team"),
                width: 600
            }).find("#txt-team").focus()
        }).on("click", n + " #btn-cancel-create-team", 
        function(e) {
            e.preventDefault(),
            mcw.dialog("hide")
        })
    })
} (jQuery),

function(e) {
    var t = "page-apply-free",
    n = "#" + t;
    e(function() {
        e(n + " textarea").autosize(),
        e("body").on("click", n + " .btn-add-attach", 
        function(t) {
            t.preventDefault();
            var n = e("p.attachment:last");
            n.clone().insertAfter(n)
        }).on("change", n + " #category", 
        function(t) {
            var n = e(this);
            n.val() === "1" ? e("#form-item-attach").show().find("input").data("validate", "required").attr("data-validate", "required") : e("#form-item-attach").hide().find("input").val("").removeData("validate").removeAttr("data-validate")
        })
    })
} (jQuery),

//付费方案 https://tower.im/teams/ca80bfd1700e46798581f20021c588cb/plans/

function(e) {
    function i() {
        var t = e(".plan-list .selected"),
        n = t.data("type") * 1,
        i = r[n],
        s = i.price;
        e("input[name=plan]").val(n);
        var o = e("#tips").removeClass("inform inform-warn inform-info").html("");
        e("button.btn-choose").prop("disabled", !1);
        var u = e("#trial").val() === "true",
        a = e("#cur-plan-type").val() * 1,
        f = e("#left-money").val() * 1,
        l = e("#cur-team-proj-num").val() * 1,
        c = i.projNum,
        h = '<a href="' + e("#select-charge-path").val() + '">付费</a>',
        p = e("#locked").val() === "true",
        d = [],
        v = [];
        if (l > c) v.push('目前团队中共有<a href="javascript:;" class="link-show-projects">' + l + "个项目</a>，请选择支持更多项目的方案");
        else if (!u && a !== -1) {
            var m = r[a],
            g = m.price,
            y = m.projNum;
            if (p) y > c ? f >= s ? d.push("我们将立即从您的团队账户中扣除 &yen;" + s + "，您的团队将马上恢复正常") : v.push("您的团队账户余额不足，请先" + h) : y < c && v.push("您的团队账户余额不足，请先" + h);
            else {
                var b = (moment(e("#next-charge-date").val()).sod().valueOf() - moment().sod().valueOf()) / 864e5,
                w = Math.floor(Math.abs(s - g) / 30 * b);
                y > c ? d.push("您选择了费用更低的方案，我们将立即退还差价 &yen;" + w + " 到您的团队账户") : y < c && (f >= w ? d.push("您选择了费用更高的方案，我们将立即从您的账户扣除升级差价 &yen;" + w) : v.push("您选择了费用更高的方案，需要支付升级差价 &yen;" + w + "，您的团队账户余额不足，请" + h + "后再试"))
            }
        }
        var E = "";
        v.length ? (e.each(v, 
        function() {
            E += "<p>" + this + "</p>"
        }), o.addClass("inform inform-warn").html(E), e("button.btn-choose").prop("disabled", !0)) : d.length && (e.each(d, 
        function() {
            E += "<p>" + this + "</p>"
        }), o.addClass("inform inform-info").html(E))
    }
    var t = "page-plans",
    n = "#" + t,
    r = [{
        price: 20,
        projNum: 5
    },
    {
        price: 99,
        projNum: 10
    },
    {
        price: 199,
        projNum: 20
    },
    {
        price: 299,
        projNum: 99
    },
    {
        price: 49,
        projNum: 5
    }];
    e(function() {
        e("body").on("click", n + " .plan-list li", 
        function(t) {
            if (!e(".form-plan").length) return;
            var n = e(this);
            n.hasClass("selected"),
            n.siblings(".selected").removeClass("selected").end().addClass("selected"),
            i()
        }).on("click", n + " .link-show-projects", 
        function(e) {
            mcw.dialog({
                el: mcw.template("tpl-projects"),
                width: 800
            })
        }).on("ajax:success", n + " .form-plan", 
        function(e, t) {
            if (t.success) return location.href = t.success_url,
            !1
        })
    }),
    mcw.pages[t] = {
        init: function() {
            var t = e("#cur-plan-type").val() * 1;
            if (t === -1 || t === 0) {
                e(".btn-choose").prop("disabled", !0);
                return
            }
            e(".plan-list li[data-type=" + t + "]").addClass("selected"),
            e(".form-plan").length && i()
        }
    }
} (jQuery),

function(e) {
    var t = "page-charge",
    n = "#" + t;
    e(function() {
        e("body").on("ajax:success", n + " .form-alipay", 
        function(e, t) {
            t.success && (location.href = t.charge_url)
        }).on("click", n + " .btn-brohao", 
        function(t) {
            var n = e("#charge-amount").val();
            mcw.dialog({
                el: mcw.template("tpl-brohao-confirm", {
                    yen: n,
                    amount: n
                })
            })
        }).on("ajax:success", n + " .form-brohao", 
        function(e, t) {
            t.success && (location.href = t.charge_url)
        }).on("click", n + " .form-brohao .btn-cancel", 
        function(e) {
            mcw.dialog("hide")
        }).on("click", n + " .charge-item", 
        function(t) {
            var n = e(t.currentTarget);
            if (n.hasClass("selected")) return;
            n.siblings(".selected").removeClass("selected").end().addClass("selected"),
            e("#charge-amount").val(n.data("charge"))
        })
    }),
    mcw.pages[t] = {
        init: function() {
            var t = e(".charge-item.year");
            t.addClass("selected"),
            e("#charge-amount").val(t.data("charge"))
        }
    }
} (jQuery),

function(e) {
    var t = "page-payment-history",
    n = "#" + t;
    e(function() {
        e("body").on("click", n + " .btn-receipt", 
        function(e) {
            mcw.dialog({
                el: mcw.template("tpl-receipt", {}),
                width: 700
            })
        }).on("ajax:success", n + " .form-receipt", 
        function(e, t) {
            t.success && mcw.dialog({
                el: mcw.template("tpl-apply-success", {
                    target_url: t.target_url
                })
            })
        }).on("click", n + " .btn-apply-ok, " + n + " .btn-edit-receipt-ok", 
        function(t) {
            mcw.stack({
                url: e(t.target).data("url"),
                replace: !0,
                root: !1,
                restorePosition: !0
            })
        }).on("click", n + " .form-receipt .btn-cancel, " + n + " .form-edit-receipt .btn-cancel", 
        function(e) {
            e.preventDefault(),
            mcw.dialog("hide")
        }).on("ajax:success", n + " .edit-receipt", 
        function(e, t) {
            mcw.dialog({
                el: t.html,
                width: 700
            })
        }).on("ajax:success", n + " .form-edit-receipt", 
        function(e, t) {
            t.success && mcw.dialog({
                el: mcw.template("tpl-edit-receipt-success", {
                    target_url: t.target_url
                })
            })
        })
    })
} (jQuery);